OK... so the
BinaryNode<T>** that the calling code passes in must contain an address that can actually be used to store the value.
&(*node)->getright()
isn't a valid address, because the return value from
getleft() is held in a temporary variable. The address of that temporary variable is of no use to you, because, well, it's temporary.
Are you trying to do it this way because you want to insert the new node at the left position? If so, you could do something like:
1 2 3 4
|
BinaryNode<T>* tmpNodePtr;
insert(&tmpNodePtr, key);
(*node)->setLeft(tmpNodePtr);
|
This assumes that the
setLeft() method simply sets the value of
this->left to the value that was passed in. If you're doing something weird with your
setLeft() method, then that might not do what you want.
Are you familiar with references? This would be a lot simpler if you used them instead:
1 2 3 4 5 6
|
BinaryNode<T>*& getleftRef(){ return left; }
template <typename T>
void BinarySearchTree<T>::insert(BinaryNode<T>*& node, T key);
insert((*node)->getleft(), key);
|
Although returning a non-const reference to a data member is breaking encapsulation, so that might not be a good idea.