我有功能,我在那里创建新的pthread
然后再使用它
void Client::initialize(Client * c) {
//some unimportant code here
pthread_t thread;
pthread_create(&thread, NULL,
c->sendMessage, (void *) fd);
//some unimportant code here
}
Client::Client() {
initialize(this);
}
sendMessage
功能:
void * Client::sendMessage(void *threadid) {
//unimportant code here
this->showHelp();
//unimportant code here
return NULL;
}
showHelp
void Client::showHelp() {
//some code
}
当我尝试编译它时,我收到此错误:
g++ -Wall -pedantic -Wno-long-long -O0 -ggdb -pthread -lncurses -g -c ./Client.cpp
./Client.cpp: In static member function ‘static void* Client::sendMessage(void*)’:
./Client.cpp:244:13: error: ‘this’ is unavailable for static member functions
make: *** [Client.o] Error 1
如果sendMessage
未声明为static
,那怎么可能呢?有什么办法吗?
答案 0 :(得分:6)
您的sendMessage
很可能在类定义中声明为静态。对于静态和非静态函数,特定成员函数定义无法区分。您必须查看类定义以区分它们。