c++ - '..' 类型的参数与 '..' C++ 不匹配

标签 c++ eclipse types arguments

<分区>

eclipse 中的 C++ 出现以下错误,我无法找出原因: ..\BakeryC++\src\controller\controller.cpp:227:20: 错误:'std::string (Repository::)()const {aka std::basic_string (Repository::)()const} 类型的参数' 不匹配 'std::string {aka std::basic_string}'

我的函数头看起来像这样:

virtual string getAsText(Product* p) = 0;

它在其他模块中被继承,但我调用它的函数只能看到这个头文件。 该函数如下所示:

string Controller::toString() const{
    return rep->toString;
}

只是为了确定,这是原始的 toString() 函数:

string IMRepository::toString() const
{
    string str = "";
    for (int i = 0; i < this->getSize(); i++)
    {
        Product* p = this->ProductList.get(i);
        if (p == NULL)
            continue;

        string name(p->getName());
        string supplier(p->getSupplier());
        char quantity[3];
        sprintf(quantity, "%d", p->getQuantity());
        string sq(quantity);
        str+=name+", "+supplier+", "+sq+"\n";
    }
    return str;
}

非常感谢任何帮助。

最佳答案

这是该错误中的重要消息。

std::basic_string (Repository::)() const does not match std::string

您返回的是函数指针,而不是函数调用的结果

改变这个

return rep->toString;

为此。

return rep->toString();

关于c++ - '..' 类型的参数与 '..' C++ 不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16152140/

相关文章:

C++ std::locale ("en") 在 iOS 上抛出异常

java - 如何绕过 Maven 的企业防火墙/代理

c++ - 有人可以向我解释一下 C++ 中复杂的函数指针类型吗

没有参数但在 Julia 中有类型的函数

c++ - 为什么 GCD 会增加执行时间?

c++ - 如何正确取消初始化 OpenSSL

c++ - 为什么在两个不同的类中调用 TinyXPath 时,同一对象会给出不同的结果?

android - 新 Android 应用程序的数据库

eclipse - Web2Py 的良好开发环境设置

node.js - 流+Webstorm "Cannot resolve module"