【问题标题】:Error C3867 Multithreading C++错误 C3867 多线程 C++
【发布时间】:2015-09-29 09:01:31
【问题描述】:

我正在尝试创建多个线程来处理点击任务。现在 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的声明吗?

标签: c++ multithreading c++11


【解决方案1】:

你得到一个指向成员函数的指针&amp;action::Chrome::click,而不是chrome-&gt;click

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

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

使用

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

【讨论】:

  • 感谢您的解释以及如何解决它。虽然将代码更改为您提供的代码,但 unique_ptr 发生错误,使用 shared_ptr 很容易修复
猜你喜欢
  • 1970-01-01
  • 2011-04-28
  • 1970-01-01
  • 2017-11-18
  • 2014-12-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-09
相关资源
最近更新 更多