问题
I'm newbie in the ansi and iso world, i compiled my program with :
-asni -pedantic -std=c++11 -std=c++98
Now, i get the following warning:
warning: converting from 'void (NetworkSocket::*)()' to 'void* (*)(void*)' [-pedantic]
for the following line:
if (pthread_create(this->threadArray, NULL, (void*(*)(void*)) &NetworkSocket::threadProcedure , (void *)this) != 0)
{ /* error */ }
How can i pass pedantic warning?
回答1:
pthread_create is a C function expecting a C function taking a void pointer, and returning a void pointer. So you can use such a C function to dispatch the call to you member function, if you use the this pointer as thread argument:
extern "C" void* startThread( void* p )
{
static_cast< NetworkSocket* >( p )->threadProcedure();
return 0;
}
if ( pthread_create( this->threadArray, 0, startThread, this ) )
...
来源:https://stackoverflow.com/questions/11701766/pedantic-warning-and-pthread-create