C++ 类型不提供调用运算符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38671031/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 14:47:01  来源:igfitidea点击:

type does not provide a call operator

c++c++11

提问by Julien Chien

I have this function, order, which returns vector<Node*>

我有这个函数order,它返回vector<Node*>

vector<Node*> order(vector<string> nodes, vector<pair<string, string>> dependencies) {
             Graph graph = buildGraph(nodes, dependencies);
             vector<Node*> order = buildOrder(graph.getNodes());
             return order;
}

and I call it like this:

我这样称呼它:

vector<Node*> order2 = order(nodes, deps);

However, the compiler gives this error:

但是,编译器给出了这个错误:

error: type 'std::__1::vector<Node *, std::__1::allocator<Node *> >' does not provide a call operator
        vector<Node*> order2 = order(nodes, deps);
                               ^~~~~
1 error generated.

What is going wrong? 'std::__1::vector<Node *, std::__1::allocator<Node *> >'seems to suggest that there is a vector<Node*, <Node*>>or something going on, but I can't seem to figure this out.

出了什么问题?'std::__1::vector<Node *, std::__1::allocator<Node *> >'似乎暗示有vector<Node*, <Node*>>什么事情正在发生,但我似乎无法弄清楚这一点。

采纳答案by Ami Tavory

It's a bit hard to tell without your posting more complete code, but consider the following:

如果不发布更完整的代码,有点难以判断,但请考虑以下几点:

int order(int j, int k)
{   
    return 3;
}   

int main(int argc, char *argv[])
{   
    char order;

    // order(2, 3);                                                
}

This code builds fine. However, uncommenting

此代码构建良好。但是,取消注释

    // order(2, 3);                     

causes it to fail, as within main, orderis a character, not a function. From the error message, it looks like you might have some similar problem.

导致它失败,因为内mainorder是一个字符,而不是功能。从错误消息来看,您可能遇到了一些类似的问题。