0

I can't make this code to compile due to an undefined reference error. The classes were more complex, but I took out the rest and its still not compiling.

I believe the problem is when trying to create a class based on a template, with new and my implementation class of that template... I really appreciate any help, cause I've lost like two hours with this.

Here is the code.

/*   the main.cpp file */

    int main() {

       // this is the line that triggers the error: "undefined reference to `ListaImp<int>::ListaImp()"

       TADLista<int> * list = new ListaImp<int>;  // this is the one
       list->Vacia();
       return 0;
    }




/* TEMPLATE CLASS */

#ifndef TADLISTA_H_
#define TADLISTA_H_

template<class T>
class TADLista {
  public:
    virtual ~TADLista(){}
    virtual void Vacia()=0;
};

 #endif /* TADLISTA_H_ */



 /*  CLASS LISTAIMP  */

 #ifndef LISTAIMP_H_
 #define LISTAIMP_H_

 #include "TADLista.h"

 template<class T>
 class ListaImp: public TADLista<T> {

   public:
     ListaImp();
    ~ListaImp();
     void Vacia();
 };
#endif /* LISTAIMP_H_ */


/* THE CPP FILE */

#include "ListaImp.h"

#define NULL 0

template<class T>
ListaImp<T>::ListaImp() {}

template<class T>
ListaImp<T>::~ListaImp() {}

template <class T>
void ListaImp<T>::Vacia(){return true;}
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Mauricio
  • 433
  • 5
  • 15
  • I just created the classes using eclipse, and included them... – Mauricio Apr 23 '15 at 03:52
  • http://pastebin.com/hhizc5FM there is the build log – Mauricio Apr 23 '15 at 04:04
  • I Solved it... Adding #include "ListaImp.cpp" at the end of the .h file did the trick... but I don't like that... between the #ifndef "bla" #define "bla" class {}; #include "ListaImp.cpp" #endif – Mauricio Apr 23 '15 at 05:10

0 Answers0