【发布时间】:2015-11-17 17:11:32
【问题描述】:
我知道该问题将被标记为重复,因为我也阅读了一些关于 SO 的类似问题。但不幸的是,没有一个答案对我有用。我尝试了所有这些,最后我想问一下。
void AsyncClass::method1()
{
cout << "method is called" << endl;
}
void AsyncClass::method2()
{
auto t = new std::thread(this->method1);
}
这两种方法都是公共的和非静态的。这不会编译说
非标准语法;使用 '&' 创建指向成员的指针
还考虑了我尝试过的关于 SO 的答案
auto t = new std::thread(this->method1);
auto t = new std::thread(this->*method1);
auto t = new std::thread(&(this->method1));
auto t = new std::thread(&AsyncClass::method1);
它们都没有编译。正确的方法是什么?
【问题讨论】:
标签: c++ member-function-pointers