64,642
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <pthread.h>
using namespace std;
class abc{
public:
abc(){
pthread_t tid;
pthread_create(&tid,NULL,mythread,NULL);
};
void *mythread(void *arg){
cout<<"hello"<<endl;
}
}
int main(){
abc myabc();
return 0;
}
#include <iostream>
#include <pthread.h>
using namespace std;
class abc{
public:
abc(){
pthread_t tid;
pthread_create(&tid,NULL,mythread,this); // 传this
};
static void *mythread(void *arg){ // 加static
(abc*)arg->threadFunc();
}
void threadFunc()
{
cout < <"hello" < <endl;
}
};
int main(){
abc myabc();
myabc.threadFunc();
return 0;
}