C2064:术语未计算为采用 1 个参数的函数 QtConcurrent::map

C2064: term does not evaluate to a function taking 1 arguments QtConcurrent::map

我正在尝试让实现 QtConcurrent 的基本程序正常工作。 发现了很多有类似问题的网站,但到目前为止,他们的解决方案中有 none 对我有效。

我的代码:

void Setup::addOne(int &i)
{
    ++i;
}

void Setup::Test()
{
    QList<int> list;
    list.append(1);
    QtConcurrent::map(list, &Setup::addOne);
}

尝试构建它显示以下错误:

C2064: term does not evaluate to a function taking 1 arguments

错误指的是qtconcurrentmapkernel.h中的以下几行:

bool runIteration(Iterator it, int, void *)
{
    map(*it);
    return false;
}

我正在使用 Qt5。感谢您的帮助。

非静态成员函数实际上有一个隐藏的参数,一个指向对象的指针,在函数内部变成 this

除非你需要访问成员变量或调用其他成员函数,否则我建议你将addOne函数设为static