可能重複:
pthread Function from a ClassG ++錯誤:在pthread_create()和成員函數指針
我試圖創建一個啓動程序的線程,但G ++不喜歡我句法。
class myClass
{
void* myFunction(void* myArg)
{
// some code, useless here
}
void start()
{
pthread_t thread_id;
int* fd;
//Some code, useless here.
pthread_create(&thread_id, 0, &myFunction, (void*) fd);
}
}
在編譯器中,g ++告訴我,ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function. Say '&myFunction'
。
對於參數3 pthread_create
,它不能將void (myClass::*) (void*)
轉換爲void* (*) (void*)
。
有什麼想法?