Hi!
I have had this problem several times before, and each time I have
been turned back forced to find another way. But not this time...
How can you cast a Class::* into a void *.
For this example I am using pthread and to start a thread you need to
pass it a void* (*)(void*)
however I have the run function inside a class:
class ThreadBase {
public:
ThreadBase() {}
virtual void run() = 0;
void start_thread() { pthread_create( &__thread_id , 0 ,this-
run , 0 ); }
void join_thread();
private:
pthread_t __thread_id;
};
Now if you inherit from this class and make a run function and call
start_thread you recieve this error:
error: cannot convert void (ThreadBase::*)() to void* (*)(void*)
This doesn't only happen with classes, if you put a function in a
namespace I believe you get a similar error.
Is there a solution, or must you solve the problem another way?
In short, you can't, nor do you want to.