#include<iostream>
#include<thread>
using namespace std;
class A
{
public:
A(int a):_a(a){}
// 需要设置为静态函数,在访问成员函数
static void f(A &a) {
a.f2();
}
void f2() {
cout << _a << endl;
}
private:
int _a;
};
int main(int argc, int * argv[])
{
A a(5);
thread t(&A::f,std::ref(a));
t.join();
system("pause");
}
Thread start function:
1. Ordinary functions
2. Function object
3. static function in class
4. lambda expression
However, the function in the member variable cannot be used as the start function of the thread