Advertisement

OOP and threads.

Started by January 14, 2001 05:12 PM
2 comments, last by GameDev.net 24 years ago
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
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
Advertisement
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
Regards,JumpsterSemper Fi
Ok, thankies!

// Poppeman

This topic is closed to new replies.

Advertisement