The most concise solution is to define in the header file shared by all your code:
template <typename T, void (T :: * M) ()>
void * thunk (
void * p)
{
T * pt = static_cast <T *> (p);
(pt -> * M) ();
return 0;
}
You probably want to define 4 versions: each where thunk returns void and void * , and each where the member function returns void and void * . That way, the compiler can do the best, depending on the circumstances (and in fact it will complain if everything doesn't match.)
Then, all you need to enter every time you run into one of the following situations:
pthread_create (& pid, 0, & thunk <Whatever, & Whatever :: doit>, & w);
This will work when the method is private if the method is referenced from class code. (If not, I need to wonder why the code refers to a private method.)
source share