您需要将类对象的非静态函数传递给新线程。原来是这样的语法,但它不起作用(弹出错误)
#include <thread>
#include <iostream>
using namespace std;
class A
{
public:
void Print()
{
cout << 'A';
}
};
int main()
{
A a;
thread new_thread(a.Print); // ERROR
new_thread.join();
return 0;
}
了解错误的本质,如何解决它 - 否
为了更清楚地传递参数,并且通常确保它有效:) - 类似于