How do i use _beginthread() inside a class without making the function static?

Started by
1 comment, last by lordcorm 16 years, 9 months ago
Ok, so how do i use _beginthread() inside a class without having to make the function i want the thread to use static, also the function that i wanna use for the thread is in the class. Its like this:

class SaidClass {
public:

void INIT();
void saidthread(void* parm);
};

void SaidClass::INIT()
{
_beginthread(saidthread,0,NULL);
}

void SaidClass:saidthread(void* parm);
{
printf("Said Class is working! \n");
}

Thanks
Advertisement
You can't pass a pointer to member function to _beginthread(). However, what you can do is pass a pointer to a static member function that uses the void * data you give to _beginthread() to call a normal member function. Ex:
class SaidClass {  public:    void INIT();    void saidthread(void);        static void thunk(void * ptr) {      reinterpret_cast<SaidClass *>(ptr)->saidthread();    }};void SaidClass::INIT() {  _beginthread(&SaidClass::thunk,0,this);}void SaidClass::saidthread(void) {  printf("Said Class is working! \n");}
Thank You :D that worked!

This topic is closed to new replies.

Advertisement