I'm writing a class called BinarySearchTree, and i'm getting strange errors from the compiler at one of the class's methods, and i would like to know
why i'm getting it. The error is " invalid conversion from ‘BinaryNode<int>*’ to ‘int’ ".
Below is the aforementioned method. The compiler gives this message at those lines, wich are in bold.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
template <class T>
void BinarySearchTree<T>::Replace(BinaryNode<T> * _replacePointer)
{
BinaryNode<T> * Pointer,seged,seged2;
if (_replacePointer -> Left != 0)
{
Pointer = _replacePointer->Left;
while (Pointer->Right != 0)
{
Pointer = Pointer->Right;
}
Pointer->Parent->Right = 0;
seged2 = Pointer->Parent;
Pointer->Parent = _replacePointer->Parent;
seged = Pointer->Left;
}
else
{
Pointer = _replacePointer->Right;
while (Pointer->Left != 0)
{
Pointer = Pointer->Left;
}
Pointer->Parent->Left = 0;
seged2 = Pointer->Parent;
Pointer->Parent = _replacePointer->Parent;
seged = Pointer->Right;
}
Pointer->Left = _replacePointer->Left;
Pointer->Right = _replacePointer->Right;
if (seged != 0)
InsertNode(Pointer,seged);
else
Rebalance(seged2);
}
|
What you should know is, that the class BinaryNode has a variable called Parent, wich is of type BinaryNode<T> * . It is a public variable.
Lets look at the line "seged2 = Pointer->Parent;" for example. seged2 is of type BinaryNode<T> *, while Pointer->Parent is of the same type. Yet, the compiler gives "invalid conversion" messgae at that line. The problem is the same at all the bold lines.
One more thing: i'm only getting these errors, if i actually
use this method somewhere.