简体   繁体   English

C++:没有匹配的函数调用

[英]C++: no matching function call

I am getting the above error and its pointing to my call for add(root, node).我收到上述错误,它指向我对 add(root, node) 的调用。 What does this error mean?这个错误是什么意思? I have tried moving the private add to the top but that doesnt work either.我曾尝试将私人添加到顶部,但这也不起作用。 Also, it cant be because its private because its in the same class, right?另外,不能因为它是私有的,因为它在同一个类中,对吧?

class Tree{

    public:
        Node *root;
        Tree(Node *r){
            root = r;
        }

        void add(Node node){
            add(root, node);//error here
        }
    private:
        void add(Node parent, Node node){

            if(parent == root && root == nullptr){
                root = node;
            }

            if(parent == nullptr){
                parent(node->value, nullptr, nullptr);
            }
            else if(node > parent){
                add(parent->right, node);
            }
            else {
                add(parent->left, node);
            }

Your function needs the signature您的函数需要签名

void add(Node* parent, Node* node)

Note that these are Node* instead of Node .请注意,这些是Node*而不是Node The same goes for the public overload of that function该函数的public重载也是如此

void add(Node* node)

This is apparent because 1) you are doing comparisons to nullptr and 2) you keep dereferencing your variables with -> instead of .这很明显,因为 1) 您正在与nullptr进行比较,并且 2) 您一直使用->而不是.

CoryKramer has spotted some errors, I'll add this also. CoryKramer 发现了一些错误,我也会添加这个。

you can't compare pointers so it should be data:你不能比较指针,所以它应该是数据:

else if(node->value > parent->value){
            add(parent->right, node);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM