I'm trying to implement a binary search tree. I'm having an issue with the destructor, which calls another function to kick off the recursive deletion of all nodes.
Compiling with
g++ -std=c++14 -pedantic
on Ubuntu
I'm getting the following error:
/tmp/ccrumI5U.o: In function 'bst::~bst()':
bst.cpp:(.text+0x7c): undefined reference to 'bst::DESTROY(bstNode*)'
collect2: error: ld returned 1 exit status
Below are the destructor and DESTROY functions:
Destructor (public):
1 2 3
bst::~bst() {
DESTROY(root);
} // END ~bst()
DESTROY (private):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
void DESTROY(bstNode* cur) {
if(cur != nullptr) {
if( (cur->left == nullptr) && (cur->right == nullptr) ) {
delete cur;
cur = nullptr;
} else {
DESTROY(cur->left);
DESTROY(cur->right);
} // END if/else
} // END if
return;
} // END DESTROY(cur)
Any advice? I have tried moving the DESTROY function to public scope and defining it before the destructor but the error persists...
WOW. Missing the scope resolution for the DESTROY function. LIne 46 of bst.cpp should be void bst::DESTROY... instead of void DESTROY... Been looking at this for an hour and a half. *sigh*