Working on implementing my own BST in C++ for the experience of dealing with such structures.
I\'ve had trouble implementing a destructor. I found in my studies, that on
Previous answers have pointed out that the unresolved external error is likely caused by a tNode destructor that is declared but not defined in a translation unit that the linker can see.
However, you have a second error: You appear to believe that setting n to null does something it doesn't do. The pointer value n is passed by value, not by reference, such that changing its value (e.g. by assigning NULL) has no effect after the function returns.
This will probably give you errors when you clear the tree and expect the root node pointer to have been set to NULL, when it remains a dangling pointer to freed memory. The result will be runtime error, not your linker error.
void BinSearchTree::Clear(tNode **N)
{
tNode * n = *N;
if (n->left != NULL)
Clear(n->left);
if (n->right != NULL)
Clear(n->right);
delete n;
*N = NULL;
size--;
}
Will do what you expect.