i get those errors when i try to compile a simple AVL tree program :
no matching function for call to A::max(A*&, A*&)
candidates are: int A::max(A&, A&)
request for member 'levels' in 'b', wich is of non-class type 'A*'
Here is the method that cause the problems :
void A::simpleLeftRotation(A & tree){
A* b = tree.leftNode;
tree.leftNode = b->RightNode;
b->rightNode = &tree;
tree.levels = 1 + max(tree.leftNode, tree.rightNode); // Problem 1
b.levels = 1 + max(b.rightNode, tree); // Problem 2
tree = b;
}
And here are my class Members :
A* righNode;
A* leftNode;
int levels;
int element;
In the line :
b.levels = 1 + max(b.rightNode, tree);
if i use the -> insted of the point operator i get :
no matching function for call to A::max(A*&, A&)
candidates are: int A::max(A&, A&)
I dont know what i am doing wrong.
Thank you.
Although you didn’t show us the declarations for all the types, I suspect this will fix the problem:
Originally, you were passing pointers in when the
maxfunction expects references. Hence, a type mismatch leading to your errors. So you need to dereference your pointers as shown.