I have function, where I create new pthread and then work with it later
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 function:
void * Client::sendMessage(void *threadid) {
//unimportant code here
this->showHelp();
//unimportant code here
return NULL;
}
declaration of showHelp
void Client::showHelp() {
//some code
}
When I try to compile it, I get this error:
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
How is that possible, when sendMessage is not declared as static ? Is there any way around?
Most likely your sendMessage is declared as static in class definition. Specific member function definitions are indistinguishable for static and non-static functions. You have to look at class definition to tell them apart.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With