1

我是 ansi 和 iso 世界的新手,我编译了我的程序:

-asni -pedantic -std=c++11 -std=c++98 

现在,我收到以下警告:

 warning: converting from 'void (NetworkSocket::*)()' to 'void* (*)(void*)' [-pedantic]

对于以下行:

if (pthread_create(this->threadArray, NULL, (void*(*)(void*)) &NetworkSocket::threadProcedure  , (void *)this) != 0)
        { /* error */      }

我怎样才能通过迂腐警告?

4

1 回答 1

2

pthread_create 是一个 C 函数,它期望 C 函数接受一个 void 指针,并返回一个 void 指针。因此,如果您使用 this 指针作为线程参数,您可以使用这样的 C 函数将调用分派给您的成员函数:

extern "C" void* startThread( void* p )
{
    static_cast< NetworkSocket* >( p )->threadProcedure();

    return 0;
} 

if ( pthread_create( this->threadArray, 0, startThread, this ) )
   ...
于 2012-07-28T14:27:21.003 回答