Problem using member function when dealing with threading
:) hi, i am new in programming and now dealing with some multi threading stuff
anyway i got problem when trying to use member function when doing threads
i searched around the net and found that 1 method is by using messages which is rather complex
another method that somebody posted is by casting:
DWORD pg_control::thr ( LPVOID lpvParam ) // static
pg_control *thr = (pg_control*)lpvParam;
// Go on with code ...
AfxBeginThread ( (AFX_THREADPROC)pg_control::thr, (LPVOID)this );}
however i get some errors
C:\Program Files\Microsoft Visual Studio\MyProjects\abc.cpp(222) : error C2440: 'type cast' : cannot convert from '' to 'unsigned int (__cdecl *)(void *)'
None of the functions with this name in scope match the target type
Error executing cl.exe.
AClient.exe - 1 error(s), 0 warning(s)
the problem lies in the red text
can anyone please correct and enlighten me?
- using winxp programming for win98se
- MFC style
- VC++6.0 SP6 :)
First of all, you need to add the & operator before pg_control::thr:
Secondly, you're using thr both as a function's name and as a local variable. This might confuse the compiler (especially if it's an older one, such as VC++). Finally, make sure that pg_control::thr is a static function. The comment says that it is, but it's worth checking pg_control.h again.
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center