简体   繁体   English

没有用于调用 &#39;std::vector 的匹配函数<node*> ::push_back(节点*&amp;)&#39;

[英]no matching function for call to ‘std::vector<node*>::push_back(Node*&)’

I am trying to push_back a node pointer into a vector , but I am getting an error, I don't know why.我正在尝试将节点指针push_backvector ,但出现错误,我不知道为什么。

Here is my code:这是我的代码:

struct Node
{
    int data;
    struct Node *left, *right;

    Node(int x){
        int data = x;
        left = right = NULL;
    }
};

vector < struct node* > par,chi,val;

void travel(struct Node* root, struct Node* parent)
{
    if(root == NULL)
    return ;

    travel(root-> left, root);

    par.push_back(parent);
    chi.push_back(root);
    val.push_back(root->data);

    travel(root-> right, root);
}

So far everything seems correct到目前为止一切似乎都是正确的

Once try to change一旦尝试改变

vector < struct node* > par,chi,val;

with

vector < struct Node* > par,chi,val;

Your code is right but has two mistake.您的代码是正确的,但有两个错误。

Replace node* with Node* while declaring a Node* type vector .替换node*Node*而声明一个Node*类型vector

vector < struct node* > par,chi,val; should be replaced with vector < struct Node* > par,chi,val;应替换为vector < struct Node* > par,chi,val;

vector < struct Node* > par,chi,val;

There is another mistake.还有一个错误。

You declared val as a Node* type vector.您将 val 声明为Node*类型向量。 But you are trying to push there an integer value.但是您正在尝试推送一个整数值。 I think it should be integer type vector.我认为它应该是整数类型的向量。 Just declare val as int type vector.只需将val声明为int类型向量。

vector < struct Node* > par,chi;
vector < int > val;

Hope it should work.希望它应该工作。

暂无
暂无

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

相关问题 没有用于调用std :: vector的匹配函数 <std::tuple> 推回 - no matching function for call to std::vector<std::tuple> push_back 没有匹配的函数调用&#39;std::vector &gt;::push_back(char&amp;)&#39; - no matching function for call to 'std::vector >::push_back(char&)' 没有匹配的 function 调用 'std::vector <std::vector<int> &gt;::push_back(int)' </std::vector<int> - no matching function for call to 'std::vector<std::vector<int> >::push_back(int)' 错误:没有匹配的 function 调用 'std::vector<float> ::push_back(std::vector<float> &amp;) 常量'</float></float> - error: no matching function for call to 'std::vector<float>::push_back(std::vector<float>&) const' 没有匹配的 function 调用 'std::vector::push_back(std::string&amp;)' - No matching function for call to ‘std::vector::push_back(std::string&)’ 没有匹配的 function 调用 'std::vector::push_back(<brace-enclosed initializer list> )'</brace-enclosed> - no matching function for call to ‘std::vector::push_back(<brace-enclosed initializer list>)’ 错误:没有匹配的函数来调用“std::vector”<x> ::push_back(y&amp;) 在 C++ - error: no matching function for call to ‘std::vector<x>::push_back(y&) in C++ 填充向量的向量时出错:没有匹配的函数来调用std :: basic_string :: push_back - Error populating a vector of vectors: no matching function to call for std::basic_string::push_back C++ - 在 foreach 中复制向量给出“没有匹配的函数来调用 std::vector<int> ::push_back(std::vector)<int> &amp;)” - C++ - copying vector in foreach gives "No matching function to call for std::vector<int>::push_back(std::vector<int>&)" 错误:没有用于调用 vector::push_back 的匹配函数 - error: no matching function for call to vector::push_back
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM