I'm getting an undefined reference to one private methods in a class. Here is a short snippet of the code (but the whole thing currently is in one source file and not separated into header and source files).
#include <iostream>
using namespace std;
struct node
{
int key_value;
node *left;
node *right;
};
class btree
{
node *root;
btree();
~btree();
void destroy_tree(node *leaf);
public:
void destroy_tree();
};
btree::btree()
{
root = NULL;
}
btree::~btree()
{
destroy_tree();
}
void btree::destroy_tree()
{
destroy_tree(root);
}
void destroy_tree(node *leaf)
{
if(leaf!=NULL)
{
destroy_tree(leaf->left);
destroy_tree(leaf->right);
delete leaf;
}
}
int main()
{
return 0;
}
The compiler outputs "undefined reference to `btree::destroy_tree(node*)' for this line:
destroy_tree(root);
but isn't the definition of that function immediately right below it?