tree *root = NULL;
root = root.Insert(root, 9);
The first statement creates a pointer and sets it to NULL, so it does not point to anything. You then try and call the
Insert
method on a NULL pointer which will always fail. You need to initialise
root
and then you can use it, but by
->
reference, not dot; thus:
tree *root = new tree(); root = root->Insert(root, 9);
However, as your code stands, this will now overwrite the root pointer so it will be lost. I suspect the Insert method needs some work, or the
node
variable in the tree class should be made public.
tree *root = new tree(); root->node = root->Insert(root, 9);
You should also remove the implementation of your classes from the header file and leave just the declarations.