I'm having problems using a simple Threading library from a book i'm reading (Mud Game Programming). It isn't working when the function I want to thread is a member of a class I create. Other than removing ThreadFunc from MyClass, how could I code around my problem?
Code:class MyClass { protected: ThreadLib::ThreadID TID_ThreadID; void ThreadFunc(void *); public: void MyFunc(); }; void MyClass::MyFunc() { TID_ThreadID = ThreadLib::Create( ThreadFunc, (void*)NULL ); } void MyClass::ThreadFunc(void *) { }Code://Related ThreadLib code //from header file namespace ThreadLib { typedef void (*ThreadFunc)(void*); typedef DWORD ThreadID; extern std::map< DWORD, HANDLE > g_handlemap; class DummyData { public: ThreadFunc m_func; void* m_data; }; DWORD WINAPI DummyRun( void* p_data ); ThreadID Create( ThreadFunc p_func, void* p_param ) { ThreadID t; DummyData* data = new DummyData; data->m_func = p_func; data->m_data = p_param; HANDLE h; h = CreateThread( NULL, 0, DummyRun, data, 0, &t ); if( h != 0 ) g_handlemap[t] = h; if( t == 0 ) { delete data; throw Exception( CreationFailure ); } return t; } } //from cpp namespace ThreadLib { std::map< DWORD, HANDLE > g_handlemap; DWORD WINAPI DummyRun( void* p_data ) { DummyData* data = (DummyData*)p_data; data->m_func( data->m_data ); delete data; return 0; } }
The error I get:
"error C3867: MyClass::ThreadFunc: function call missing argument list; use '&MyClass::ThreadFunc' to create a pointer to member"
The error I get if it's &MyClass::ThreadFunc
"error C2664: 'ThreadLib::Create' : cannot convert parameter 1 from 'void (__thiscall MyClass::* )(void *)' to 'ThreadLib::ThreadFunc'
There is no context in which this conversion is possible"
The error I get if i try to cast it to a void*
"error C2440: 'initializing' : cannot convert from 'void (__thiscall MyClass::* )(void *)' to 'void *'"
<edit> The posted ThreadLib only shows what was defined as win32. I removed all defines, if/else, for anything other than win32 to make it easier to read. The author wrote the library for both windows and linux.



LinkBack URL
About LinkBacks



