doblesesays
doblesesays

Reputation: 1

"error: expected class-name before '{' token" trying to inheritance

I tried to create a queue that inherits from list and get this error:

"error: expected class-name before '{' token"

these are the codes that I have ...

cola_lista.cpp

#ifndef cola_hereda_lista
#define cola_hereda_lista

#include <iostream>
#include "lista_t.hpp"
//#include "nodo_t.hpp"

using namespace std;

template <class T>

class cola : public lista{
    private:
        nodo<T> *frente, *final;
    public:
        cola();
        bool es_vacia();
        int longitud(); //  
        void encolar(T e);
        void desencolar(); //precondicion ¬es_vacia
        T obtener_frente(); //precondicion ¬es_vacia
        ~cola();    
};

#endif

lista.hpp

#ifndef lista_template
#define lista_template

#include <iostream>
#include "nodo_t.hpp"

using namespace std;

template <class T>

class lista{
    private:
        nodo<T> *primero, *ultimo;
        int cantidad;
    public:
//
};

nodo.hpp

#include <iostream>

#ifndef nodo_template
#define nodo_template

using namespace std;

template <class T>

class nodo{
    private:

        T elemento;
        nodo<T> *siguiente;

    public:

        nodo();
        T get_elem();
        void set_elem(T e);
        nodo<T>* get_siguiente();
        void set_siguiente(nodo<T> *sigui);
        ~nodo();
};

I've been hours trying to figure out what is what is ill-posed in the code. Help!

Upvotes: 0

Views: 590

Answers (2)

Shafik Yaghmour
Shafik Yaghmour

Reputation: 158469

You need to adjust your declaration of cola:

template <class T>
class cola : public lista<T>
                         ^^^

cola is a class template and you need to specify the type. Also you should not put using namespace std; in your header files and I would discourage you from using it in general, this previous thread Why is 'using namespace std;' considered a bad practice in C++? goes into why.

Upvotes: 0

Sergi0
Sergi0

Reputation: 1096

change your code to this

template <class T>
class cola : public lista<T>{

Upvotes: 1

Related Questions