error: expected constructor, destructor, or type conversion before '*' token

报错:error: expected constructor, destructor, or type conversion before '*' token

class AVLTree
{
private:
    struct BTNode
    {
        int key;
        struct BTNode *left;
        struct BTNode *right;
        int height;
    };
    struct BTNode *root;
public:

    AVLTree();
    ~AVLTree();
    int height(BTNode* N);
    int getBalance(BTNode* N);
    BTNode* newNode(int val);
    BTNode* insertToTree(BTNode* node,int val);
    void insert(int val);
    void destroyAVLTree(BTNode* N);
    BTNode* llRotate(BTNode* y);
    BTNode* rrRotate(BTNode* y);
    BTNode* lrRotate(BTNode* y);
    BTNode* rlRotate(BTNode* y);

    int max(int a,int b)
    {
        return a>b?a:b;
    };
};

BTNode* AVLTree::newNode(int val)
{
    struct BTNode *p = new BTNode;

    p->key = val;
    p->height = 1;
    p->left = NULL;
    p->right = NULL;
    return p;

}

原因是函数定义BTNode没有加  AVLTree::

AVLTree::BTNode* AVLTree::newNode(int val)
{
    struct BTNode *p = new BTNode;

    p->key = val;
    p->height = 1;
    p->left = NULL;
    p->right = NULL;
    return p;

}

这样就好了

你可能感兴趣的:(C++)