Error C3867 Multithreading C++

Error C3867 Multithreading C++

本文关键字:C++ Multithreading C3867 Error      更新时间:2023-10-16

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

C3867 'action::Chrome::click': non-standard syntax; use '&' to create a pointer to member

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]);