0

I've wrote my code nad when I want to build it it says: unresolved external symbol" for some functions, like the destructor:

header file:

template <class T> class Tree
{
*not important*
public:
    ~Tree()
}

cpp file:

template <class T>
Tree<T>::~Tree()
{
    if (root != NULL)
    clear(root);
}

I also defined and clear function so thats not the problem..

  • You didn't include the `.cpp` file in the build (well, link)? Or you didn't `#include` the header in the `.cpp`? Please create a full [MCVE](http://stackoverflow.com/help/mcve) and include all the error messages in your question. There isn't enough information here to answer. – BoBTFish Feb 08 '16 at 11:23
  • What about `;` after that `~Tree()` in the header file? – barak manos Feb 08 '16 at 11:24
  • forgot to write in the question but in the code there is ; – David Cohen Feb 08 '16 at 11:25
  • @DavidCohen Please show a full, *real* example (one that you have actually tried to compile, and gives you the error messages) in the question, along with the full error messages. – BoBTFish Feb 08 '16 at 11:26
  • what do you mean? post the full code? it's long – David Cohen Feb 08 '16 at 11:26
  • and I've included everything.. – David Cohen Feb 08 '16 at 11:27
  • @DavidCohen Not the full code, you should create a minimal example that exhibits the problem. I posted a link to [MCVE](http://stackoverflow.com/help/mcve) above (and here). If you try to type in something that looks a bit like your problem into the question without actually trying it, you may 1) not include the real cause of the problem, and 2) include other errors that we spot, so we miss the real error. (But the answer is already in the duplicate anyway, so don't bother now, but bear in mind for future questions please). – BoBTFish Feb 08 '16 at 11:37
  • something like this? header: #include using namespace std; template class Tree { protected: template class Node { public: Node *left; Node *right; T Value; Node(T val) : value(val), left(NULL), right(NULL){}; Node(T val, Node *l, Node *r) : value(val), left(l), right(r){}; }; Node *root; public: Tree() { root = NULL; } ~Tree(); }; cpp file (destructor define): #include #include"Tree.h" using namespace std; template Tree::~Tree() { if (root != NULL) clear(root); } – David Cohen Feb 08 '16 at 11:45
  • Hmm its doesn't look good Im new here and don't know much what to post... – David Cohen Feb 08 '16 at 11:45
  • Move the implementation in header. – zdf Feb 08 '16 at 12:41

0 Answers0