这是我的代码 我已经在相应的行旁边写下了发生的错误消息
//AVL Tree implemantation
template<class Element>
class AVLtree
{
public:
int height(AVLnode<Element>*)const;
int max(int,int)const;
};
//Function to get the max
template<class Element>
int AVLtree<Element>::max(int a, int b)
{
return ((a>b)?a:b);
} //Error:'AVLtree<Element>::max' : unable to resolve function overload
//Function to calculate the height
template<class Element> //Error:error C2954: template definitions cannot nest
int AVLtree<Element>::balanceFactor(AVLnode<Element>* p)
{
return (height(p->left) - height(p->right));
}
最佳答案
第一个错误是您将 max()
声明为 const
成员函数,但您试图将其定义为非 const
成员函数。您需要在定义中添加 const
:
template<class Element>
int AVLtree<Element>::max(int a, int b) const {
return std::max(a, b);
}
我不太明白另一个错误,但它可能是由前面的错误引起的。由于它使用的名称未在发布的类的摘录中声明,因此它也可能有所不同。
关于c++ - 我一直在尝试实现和 AVL 树,但我不断收到这 2 个错误 C2954 和 C2955,并且不知道如何解决它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24984199/