I am getting the above error and its pointing to my call for add(root, node). What does this error mean? I have tried moving the private add to the top but that doesnt work either. Also, it cant be because its private because its in the same class, right?
class Tree{
public:
Node *root;
Tree(Node *r){
root = r;
}
void add(Node node){
add(root, node);//error here
}
private:
void add(Node parent, Node node){
if(parent == root && root == nullptr){
root = node;
}
if(parent == nullptr){
parent(node->value, nullptr, nullptr);
}
else if(node > parent){
add(parent->right, node);
}
else {
add(parent->left, node);
}
Your function needs the signature
Note that these are
Node*
instead ofNode
. The same goes for thepublic
overload of that functionThis is apparent because 1) you are doing comparisons to
nullptr
and 2) you keep dereferencing your variables with->
instead of.