It's const correctness issues.
const member functions can not change member vars, and they can only call other const member functions. A const function cannot call a nonconst function on the same object.
Here, you have
inorder()
(a const function) calling
inorder(Node<T>*&)
(a non-const function). This is not allowed, hence the error.
The solution here is to make both inorder() functions const.
Also...
1 2 3 4 5
|
template <typename T>
void BSearch<T>::inorder () const
{
inorder (r);
}
|
Since
this
is const (because the function is const), that means the member 'r' will be const as well, which means you won't be able to pass it as a nonconst reference. A solution here would be to change inorder:
1 2 3 4 5
|
//template <typename T>
//void BSearch<T>::inorder (Node <T> * & r) // bad
template <typename T>
void BSearch<T>::inorder (const Node <T> *r) const // good
|
Notice I make the function const, and I pass just a const pointer, not a non-const reference to a pointer (no need for the reference here).
Also... it's a really bad idea to name your member 'r'. It's not very descriptive at all. It's especially confusing since you use 'r' for all your parameter names.