C++ 下编译pthread的问题
开始我是这样写的
void* startListen(void *)
{
........
}
/////
pthread_create(&socketListen,NULL, startListen, NULL);
这个时候是可以正常编译的,也能执行。
可是我想把它写到一个类中封装起来,改为如下:
void* AcdSocket::startListen(void *)
{........}
pthread_create(&socketListen,NULL, (void *)startListen, NULL);
报错:
错误: invalid use of member (did you forget the ‘&’ ?)
//////////
再改为:
void AcdSocket::startListen(void *)
{........}
pthread_create(&socketListen,NULL, (void *)&startListen, NULL);
报错:
错误: 从类型 ‘void*’ 到类型 ‘void* (*)(void*)’ 的转换无效
编译语句:
g++ main.cpp acdsocket.cpp -lpthread -o acd
g++版本
g++ (GCC) 4.0.3 (Ubuntu 4.0.3-1ubuntu5)
系统:
ubuntu 6.06