在C++的类中,普通成员函数不能作为pthread_create的线程函数,如果要作为pthread_create中的线程函数,必须是static

在qt写一个聊天程序的时候使用pthread_create来群发消息时,一直报错,后来仔细学习了pthread_create发现普通成员函数不能作为pthread_create的线程函数,如果要作为pthread_create中的线程函数,必须是static。

 static void * send_msg(void * arg);
 static void * recv_msg(void * arg);
pthread_create(&snd_thread, NULL, send_msg, (void *)&sock);
pthread_create(&rcv_thread, NULL, recv_msg, (void*)&sock);

你可能感兴趣的:(c++)