Possible Duplicate:
function pointer for a member function
I have a problem, in a class, I have this method : virtual void start(void *(*ptr)(void*), void *);
In an other one, I want to call start with this method : void *Room::run(void *p).
So I tried to do this : thread->start(&Room::run, 0); but the compiler doesn’t want it because : cannot convert parameter 1 from 'void *(__thiscall Room::* )(void *)' to 'void *(__cdecl *)(void *)'
How can I resolve it ? Templates ? Or is there a more obvious solution ?
Thank you !
P.S : Just to precise, I need it to make threads (http://linux.die.net/man/3/pthread_create).
In C++, pointers to (freestanding) functions and pointers to methods are completely different beasts that can not be mixed.
If you want to pass a pointer-to-member-function to an API that needs a pointer-to-function, then the typical solution is to use a small wrapper function:
And you use it like this: