invalid conversion from ‘BinaryNode<int>*’ to ‘int’

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.
Last edited on
seged and seged2 are NOT pointers because of the way you made the declartion in Line 7.
I think gulkan means line 4.
It should be:
BinaryNode<T> * Pointer, * seged, * seged2;
Oops - line 4 it is.
Thank you, this really helped.

I tought that

BinaryNode<T> * Pointer, seged, seged2; is the same as

BinaryNode<T> * Pointer;
BinaryNode<T> * seged;
BinaryNode<T> * seged2;

No. That is the whole basis of some peoples' arguments that the asterisk goes with the variable name not the type. Ie:

1
2
3
int* pInt;    // Some people put the "*" right next to the type with no space
int *pInt;    // Others put it right next to the variable name with no space
int * pInt;   // And still others are undecided so they put spaces on both sides 


So
 
int  *pInt, anInt;


declares pInt to be a pointer to an integer and anInt to be an integer.
Topic archived. No new replies allowed.