Jump to content
  • Advertisement
Sign in to follow this  
lordcorm

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

This topic is 4022 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
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!