Nadim
Nadim

Reputation: 11

I've been trying to implement and AVL Tree but I keep on getting these 2 errors C2954 and C2955 and don't know how to solve them

Here is my code I have written the error messages that occured next to the corresponding lines

//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));
}

Upvotes: 0

Views: 90

Answers (1)

Dietmar K&#252;hl
Dietmar K&#252;hl

Reputation: 153840

The first error is that you declared max() to be a const member function but you are trying to define it as a non-const member function. You'll need to add const to in the definition:

template<class Element>
int AVLtree<Element>::max(int a, int b) const {
    return std::max(a, b);
}

I can't make much sense of the other error but it may have resulted from the preceding error. Since it uses a name not declared in the excerpt of the class posted, it may also be something different.

Upvotes: 2

Related Questions