Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

poppeman

OOP and threads.

This topic is 6426 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

Howdy ho! I''m currently practicing OOP, DirectX, Windows programming in general, etc. Now I have run into a little problem when I tried using multithreading and OOP. Here''s a code snippet: class CEngine { DWORD WINAPI Gameloop(LPVOID arg); public: bool Init(); }; DWORD WINAPI CEngine :: Gameloop(LPVOID arg) { } bool CEngine :: Init() { DWORD threadid; CreateThread(0, 0, Gameloop, 0, 0, &threadid); return true; } That code results in some really groovy error message from the compiler (can''t typecast). Tried to typecast it directly, creating a pointer to Gameloop, etc, etc but nothing works. Any idea? // Poppeman

Share this post


Link to post
Share on other sites
Advertisement
Yeah, member functions of a class are in a different format than standard C-style functions. Member functions have an implicit "this" passed as the first argument.

The easiest way to fix this is to 1) Make the member function static (but then you won''t be able to use member variables, or:
2) Use something like this: http://dd.quakex.com/methodthread.txt

The second option is a bit more complex, but it works rather well

--Rob

Share this post


Link to post
Share on other sites
check out the Thread Class on glVelocity (link on the main page) too. It has a CLASS Thread setup like you''re wanting as well.

Regards,
Jumpster

Share this post


Link to post
Share on other sites

  • 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!