std::thread 调用类的成员函数需要传递类的一个对象作为参数:
#include <thread>
#include <iostream>
class bar {
public:
void foo() {
std::cout << "hello from member function" << std::endl;
}
};
int main()
{
std::thread t(&bar::foo, bar());
t.join();
}
如果是在类的成员函数中处理thread,传入 this 即可,如:
std::thread spawn() {
return std::thread(&blub::test, this);
}