• Advertisement
Sign in to follow this  

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

This topic is 3931 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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");
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement