gpt4 book ai didi

c++ - 我不明白声明 avl 树时的错误信息

转载 作者:行者123 更新时间:2023-11-30 05:15:14 26 4
gpt4 key购买 nike

我正在尝试对 AVL 树进行编程,但我遇到了这个我不明白的错误,有人可以帮忙吗?谢谢

source

enter image description here

template<class KeyType, class ItemType>
class AVL
{
protected:
template<class KeyType, class ItemType>
class AVLNode
{
public:
AVLNode(KeyType key, ItemType item) :
m_Balance(0), m_Depth(0),
m_Key(key), m_Data(item),
m_pLeft(0), m_pRight(0)
{
}

KeyType m_Key;
ItemType m_Data;

AVLNode* m_pLeft;
AVLNode* m_pRight;
};

AVLNode<KeyType, ItemType>* m_pRoot;
public:
AVL() : m_pRoot(0) { }
~AVL() { }
};

最佳答案

尝试进行以下更改:

template<class KeyType, class ItemType>
class AVL
{
protected:
// Unnecessary -> template<class KeyType, class ItemType>
class AVLNode
{
public:
AVLNode(KeyType key, ItemType item) : m_Balance(0), m_Depth(0),
m_Key(key), m_Data(item),
m_pLeft(0), m_pRight(0)
{ }

private:
int m_Balance; // Missing from the ctor declaration
int m_Depth; // Missing from the ctor declaration
KeyType m_Key;
ItemType m_Data;

AVLNode<KeyType, ItemType>* m_pLeft; // Change here
AVLNode<KeyType, ItemType>* m_pRight; // Change here
};

AVLNode<KeyType, ItemType>* m_pRoot;
public:
AVL() : m_pRoot(0) { }
~AVL() { }
};

关于c++ - 我不明白声明 avl 树时的错误信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43176110/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com