我有功能,我创建新的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);
}
Run Code Online (Sandbox Code Playgroud)
sendMessage 功能:
void * Client::sendMessage(void *threadid) {
//unimportant code here
this->showHelp();
//unimportant code here
return NULL;
}
Run Code Online (Sandbox Code Playgroud)
宣言 showHelp
void Client::showHelp() {
//some code
}
Run Code Online (Sandbox Code Playgroud)
当我尝试编译它时,我收到此错误:
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
Run Code Online (Sandbox Code Playgroud)
这怎么可能,什么时候sendMessage不被宣布static?有什么办法吗?