获取错误:即使函数不是静态的,"this"也不能用于静态成员函数

Mar*_*cek 2 c++ pthreads

我有功能,我创建新的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?有什么办法吗?

AnT*_*AnT 6

最有可能的sendMessage 声明为类定义静态的.对于静态和非静态函数,特定成员函数定义无法区分.您必须查看类定义以区分它们.