I have a ClassB which have a thread object and a function defined as:
pthread_t m_thWorkThread;
void* ThreadProc(void *);
And in the constructor of ClassB, I create a thread like:
pthread_create(&m_thWorkThread, NULL, &(ClassB::ThreadProc), this);
However I got two error messages:
error: ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function.
cannot convert âvoid* (ClassB::)(void)â to âvoid* ()(void)â for argument â3â to âint pthread_create(pthread_t*, const pthread_attr_t*, void* ()(void), void*)â pthread_create(&m_thWorkThread, NULL, &(ClassB::ThreadProc), this);
However if I define the function as static, it does not complain:
static void* ThreadProc(void *);
However I do not want it to be static, since I will create multiple threads and I want each thread has a separate ThreadProc function.