c++11 - Undefined Reference issue with C++ and Netbeans -
i have following files:
listaenc.hpp
#include "elemento.hpp" #include <cstdlib> #include <iostream> template<typename t> class listaenc { public: listaenc(); ~listaenc(); ... } //implementation: template<typename t> listaenc<t>::listaenc() { head = null; size = 0; } template <class t> listaenc<t>::~listaenc() { }
main.cpp:
#include "listaenc.hpp" using namespace std; int main(int argc, char** argv) { listaenc<int>* teste = new listaenc<int>(); return 0; }
poligono.hpp
#ifndef poligono_hpp #define poligono_hpp #include "ponto.hpp" #include "listaenc.hpp" #include <string> using namespace std; public: //construtores poligono(listaenc<ponto> pontos, string nome); poligono(const poligono& orig); virtual ~poligono(); //metodos string obternome(); void adicionarponto(ponto); listaenc<ponto> obterpontos(); private: listaenc<ponto> pontos; string nome; }; #endif /* poligono_hpp */
poligono.cpp
#include "poligono.hpp" * poligono::poligono(listaenc<ponto> pontos, string nome) { this->pontos = pontos; this->nome = nome; } * poligono::poligono(const poligono& orig) { } * poligono::~poligono() { } //metodo string poligono::obternome() { return this->nome; } listaenc<ponto> poligono::obterpontos() { return this->pontos; } void poligono::adicionarponto(ponto p) { this->pontos.adiciona(p); }
i these compile errors on poligono.cpp:
/home/mariana/netbeansprojects/trabalhocg/poligono.cpp:12: undefined reference `listaenc::~listaenc()'
the destructor listaenc empty, implemented. know how solve problem?
edit: added implementation of constructor , destructor listaenc. error appears in bit of code added poligono.cpp, listaenc 1 of parameters.
edit2: have added asterisk points in poligono.cpp error appears (the first constructor, second constructor , destructor)
since posted code shows
#ifndef poligono_hpp #define poligono_hpp
in poligono.cpp
, don't have same in listaenc.hpp
, assume missing include guards in header?
depending on other code included in poligono.cpp
, result in definition of template listaenc
twice. under c++ standard if break 1 definition rule may linking error , no other diagnostic message.
so, maybe make sure there include guards in listaenc.hpp
?
if post more code update answer :)
edit: suggestion, if having trouble finding dtor definition of listaenc
, might try moving implementation of class body? makes less typo cause lost. since code in header doesn't change otherwise.
Comments
Post a Comment