Strange "Undefined reference" error on C++ Netbeans project -
this question has answer here:
the solution duplicate question did not work
i have following files:
listaenc.hpp
#include "elemento.hpp" template<typename t> class listaenc { public: listaenc(); ~listaenc(); // inicio void adicionanoinicio(const t& dado); t retiradoinicio(); void eliminadoinicio(); t pegarhead(); // posicao void adicionanaposicao(const t& dado, int pos); int posicao(const t& dado) const; t* posicaomem(const t& dado) const; bool contem(const t& dado); t retiradaposicao(int pos); // fim void adiciona(const t& dado); t retira(); // especifico t retiraespecifico(const t& dado); void adicionaemordem(const t& data); // outras bool listavazia() const; bool igual(t dado1, t dado2); bool maior(t dado1, t dado2); bool menor(t dado1, t dado2); void destroilista(); int pegartamanholista(); private: //trocar pra private elemento<t>* head; int size; };
listaenc.cpp
#include "listaenc.hpp" #include <cstdlib> #include <iostream> template<typename t> listaenc<t>::listaenc() { ... }
main.cpp
#include "listaenc.hpp" using namespace std; int main(int argc, char** argv) { double x1, y1; x1 = 2; y1 = 4.2; listaenc<int>* teste = new listaenc<int>(); return 0; }
this should compile fine, undefined reference error listaenc on main.cpp. have more files in reference listaenc undefined, tried isolating , still can't work. understand why happening?
edit: more specifically, there undefined error constructor , destructor of listaenc
you can't separate declaration implementation when instantiate template class. combine code single file , include in main.cpp.
or, go step further , implement functions inline in class declaration if suits coding style.
Comments
Post a Comment