I will assume that bstt::Root
is declared as NODE*
, as this seems most likely.
The second parameter to _postordercopy
is of type const NODE*&
, a reference to a pointer to a constant NODE
. What is the type of the argument you try to pass in? Since other
is declared const
, each of its members is const
. So other.Root
is a constant pointer to NODE
, also known as NODE* const
– the const
is tacked on the far right of the declared type. This is incompatible with the parameter type. (See What is the difference between const int*
, const int * const
, and int const*
? for a more thorough discussion of this distinction.)
The problem is that a non-constant reference cannot be initialized from a constant. Since other
has to be const
, you'd need to change the type of the function parameter to match what you give it. One solution is to move const
so that it qualifies the pointer rather than the pointer-to object: NODE* const &
. Another solution is to remove the ampersand, as that is a bit wasteful in this case: const NODE*
. (The reference adds an extra layer of indirection that provides no benefit.) Think about what your function is supposed to do, and const
-qualify whatever is supposed to not change. In this case, the node pointed to by the second parameter should not change.
While that resolves your immediate compiler error, there are other errors to address in your code. In addition, I would consider adding two accessor functions to get the root node. These functions could enforce const
in a way that you do not get when accessing Root
directly.
NODE *& get_root() { return Root; }
const NODE * const & get_root() const { return Root; }
The main difference is that the type of other.Root
is NODE * const
, which drops the const
-qualifier for the node, whereas other.get_root()
would yield a const NODE * const
, which propagates the qualifier. At the same time, this->get_root()
would yield a simple NODE*
since this
is not const
-qualified. You get to use the same syntax, and the const
-ness is propagated appropriately.