Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/138.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 获取错误:‘;这’;对于静态成员函数不可用,即使函数不是静态的_C++_Pthreads - Fatal编程技术网

C++ 获取错误:‘;这’;对于静态成员函数不可用,即使函数不是静态的

C++ 获取错误:‘;这’;对于静态成员函数不可用,即使函数不是静态的,c++,pthreads,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::Clien

我有一个函数,在这里我创建了新的
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);
}
发送消息
功能:

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
时,这怎么可能呢?有办法吗

您的
发送消息很可能在类定义中声明为静态。静态函数和非静态函数的特定成员函数定义无法区分。您必须查看类定义才能将它们区分开来。

您的类定义是什么?我敢打赌,它将
sendMessage
声明为
static
。我将在一分钟内更新我的帖子。您可能希望在
pthread\u create
调用中也使用
&Client::sendMessage
,尽管您无法传递成员函数指针。在声明中它将是静态的。。。在定义中使用关键字static是为了其他目的,因此发生此错误时不要在定义中搜索:)有趣的是,您决定省略
sendMessage
的声明,其中
static
说明符是……好吧……我是个白痴……我花了2个小时寻找可能出错的地方,当然我在头文件x-中将其声明为static)