0

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!

FDinoff
  • 30,689
  • 5
  • 75
  • 96

2 Answers2

1

change your code to this

template <class T>
class cola : public lista<T>{
Sergi0
  • 1,084
  • 14
  • 28
  • It worked! I'm sure I had tried that before. I guess I must have something wrong. Thank you. Now, a little doubt ... ... In **cola_lista.cpp** I have commented # include nodo.hpp That's good, right? Since **lista.hpp** previously included. – doblesesays May 12 '13 at 01:48
0

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.

Community
  • 1
  • 1
Shafik Yaghmour
  • 154,301
  • 39
  • 440
  • 740
  • Yes, now if compiles fine. Thank you! I have commented # include nodo.hpp That's good, right? Since lista.hpp Previously included. – doblesesays May 12 '13 at 01:54
  • @Geekne reduces unnecessary includes is good but if you have proper include guards which it looks like you do then it should not matter. – Shafik Yaghmour May 12 '13 at 02:10