我得到的錯誤,當我嘗試編譯一個簡單的AVL樹方案:指針和引用錯誤在C++
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*'
下面是導致這些問題的方法:
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;
}
這裏是我班成員:
A* righNode;
A* leftNode;
int levels;
int element;
在行:
b.levels = 1 + max(b.rightNode, tree);
如果我用 - > insted的點操作,我得到:
no matching function for call to A::max(A*&, A&)
candidates are: int A::max(A&, A&)
我不知道我做錯了。
謝謝。
謝謝大家。 Mysticial的答案是最完整的一個 –