OOP and threads.
January 14, 2001 05:12 PM
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement