Advertisement

Passing member function to CreateThread

Started by December 01, 2003 10:05 AM
0 comments, last by Ironica 21 years, 2 months ago
Hey, just came across a small problem. I have a C++ object, which creates a new thread (within constructor). But the new thread runs a member function. This:

CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) this->loopThread, NULL, 0, &threadID);
 
gives me this error: "error C2440: ''type cast'' : cannot convert from ''overloaded-function'' to ''LPTHREAD_START_ROUTINE'' None of the functions with this name in scope match the target type" Now I did manage to get this to compile, by casting to void:

CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) (void) this->loopThread, NULL, 0, &threadID);
 
However, the function doesn''t actually run! I suppose I could have the loopThread function seperate from the object, but I thought it would be better to keep this nice and object orientated =) Anyone tell me how to get around this, without creating seperate outside functions?
http://www.gamedev.net/community/forums/topic.asp?topic_id=193842

This topic is closed to new replies.

Advertisement