I whipped this up - it should give you some ideas (or you can use this).
Code:
//thread function pointer data type
typedef void (*thread_func_t)(void*);
//Base thread class
class BaseThread
{
//thread function that calls run() interface
static void thread_func(void *thisp) {reinterpret_cast<BaseThread*>(thisp)->run();}
public:
//overloaded cast operator for thread function type
operator thread_func_t() {return thread_func;}
//overloaded cat operator for thread function data (void*)
operator void*() {return reinterpret_cast<void*>(this);}
//"run" interface for thread
virtual void run() {cout << "BaseThread run" << endl;}
};
//Thread extension, implementing it's own run()
class MyThread : public BaseThread
{
public:
virtual void run() {cout << "MyThread run" << endl;}
};
//test "pthread_create" function
void run(thread_func_t tf,void *data) {tf(data);}
int main()
{
MyThread mt;
BaseThread bt;
run(bt,bt);
run(mt,mt);
return 0;
}
/*
This will output:
BaseThread run
MyThread run
*/
gg