1)
Isn't a pointer an address itself. When I am passing a address, should it not work?
2)
If I try to change the above function prototype for passing pointer by reference, like
void BSTree::AddNode(int a, Node * & ptr )
i still get some error when calling it with statement
tree.AddNode(5,tree.getRoot());
The error says "No matching functio to call". I usually don't have to make any changes to 'function calling' when pass by reference is used. What is the appropriate way to make the two work together?
The problem I see is you never set root when you add the first node.
You probably should have 2 functions for AddNode instead of 1. AddNode(int a) would check to see if the root is null. If so, create a node and store it as root. If root is not null, call the other AddNode function, passing it the right or left branch pointer, as necessary (or just returning if a = root->getData()).
Edit: I think this is the same thing ne555 is trying to say, but with different words.
You are copying the pointer and modifying the copy, so the original remains unchanged.
> i still get some error when calling it
> The error says "No matching functio to call".
¿description of the function match?
¿candidates?
That information was (or should have) in the error message of your compiler. If you do not understand something that's more a reason to not edit it away.
You cannot bind a non-constant reference to a temporary.
`getRoot()' returns a copy of the root pointer, a temporary.
> I think this is the same thing ne555 is trying to say
no.