c++ - 错误 C3867 多线程 C++

标签 c++ multithreading c++11

我正在尝试创建多个线程来处理点击任务。现在 Visual Studio 2015 不显示语法错误,但是在编译时出现错误

C3867 'action::Chrome::click':非标准语法;使用“&”创建指向成员的指针

int main()
{
    std::unique_ptr<action::Chrome>chrome(new action::Chrome());
    const std::vector<uint_16>xLocation = { 1155, 1165, 1205, 1245, 1285 };
    std::vector<uint_16>yLocation;

    //Fill yLocation
    //Yada yada, other code

    std::thread task[6];
    for(uint_8 i = 0; i < 6; i++)task[i] = std::thread((chrome->click, xLocation, yLocation[i]));
    for(uint_8 i = 0; i < 6; i++)task[i].join();
}

最佳答案

您使用 &action::Chrome::click 获取指向成员函数的指针,而不是 chrome->click

如果您传递指向成员函数的指针,则第二个参数应该是函数被“调用”的对象。

你的参数列表也有问题;额外的括号意味着您只是将 yLocation[i] 传递给线程的构造函数。

使用

std::thread(&action::Chrome::click, chrome, xLocation, yLocation[i]);

关于c++ - 错误 C3867 多线程 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32839928/

相关文章:

c++ - "this"指针上的指针运算

c++ - 如何将派生类的 shared_ptr vector 转换为基类的 shared_ptr vector

c++ - 拥有 constexpr 静态字符串会导致链接器错误

c++ - 分配 C++ 对象数组

c++ - c++中一个dll的多个实例

c++11 - 模板成员函数中的 lambda 错误

c++ - C++ 中的 "was not declared in this scope"

java - android在进度条期间显示对话框

C++11 线程队列

c++ - 关于 new 和 delete 的使用,以及 Stroustrup 的建议