0
如何将成员函数作为参数传递给pthread_create函数?如何将对象的成员函数作为参数传递给pthread_create?
实施例:
class A
{
public:
A(){}
void funcForThread(Person p) {
//code...
}
void createThread(Person p) {
pthread_t thread1;
pthread_attr_init (&attr);
pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_JOINABLE);
pthread_create (&thread1, &attr, /* what to write here*/); // need to pass funcForThread and Person p object there
}
private:
pthread_attr_t attr;
};
这不是C,因为C没有类或成员函数。 – Barmar
您需要传递代理功能。 – Barmar
@Barmar我不知道代理功能是什么,请你提供一个例子吗? – stilltryingbutstillsofar