BST on c++ error

BST on c++ error

本文关键字:error c++ on BST      更新时间:2023-10-16

我试图在 cpp 上创建 BST我在类树中完成了类节点,因为它是合乎逻辑的。页眉:

class Node;
class Tree
{
public:
    Node* root;
    Tree();
    Tree(int val);
    void insert(int val);
    class  Node
    {
    public:
        Node();
        Node(int val);
        Node* right;
        Node* left;
        int val;
    };
};

鼓掌:

Tree::Tree()
{
    this->root = NULL;
}
Tree::Node::Node()
{
}
Tree::Node::Node(int val)
{
    this->val = val;
    this->left = NULL;
    this->right = NULL;
}
void Tree::insert(int val)
{
    this->root = new Node(3);
}

我在

this->root = new Node(3);

IntelliSense: a value of type "Tree::Node *" cannot be assigned to an entity of type "Node *"   
error C2440 : '=' : cannot convert from 'Tree::Node *' to 'Node *'  

请问我做错了什么?根此节点*和新节点 (3) 返回节点*问题出在哪里?谢谢!!!

据我了解,在您当前的实现中,您声明了两个名为 Node 的类; 一个在全局范围内,而另一个在类Tree的作用域中。这可以通过仅使用一个类来解决。

相关文章: