Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

class & thread

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
diplox (Visitor) May 17, 2001
I'm programming a threaded class but I can't use non-static class function in my thread.
e.g:

void MyClass::dummy()
{
cout <<&quot;lauched...&quot;<<endl
}

void MyClass::launch_thread()
{
mythread = CreateThread( NULL,0,LPTHREAD_START_ROUTINE) dummy,null,0,&dwThreadId);
}

if &quot;dummy&quot; is declared non-static, the systeme say:
&quot;error C2440: 'type cast' : cannot convert from '' to 'unsigned long (__stdcall *)(void *)'&quot;

Has anybody samples which use class method in thread creating. How can I do the cast ?
Someone advises me to overload the operator (), but how can I do that ?

thanks for your answers

dams
 
class x
{
public:
neededfunc();
static DWORD WINAPI ThreadFx(LPVOID);
void launch_thread();

}
DWORD WINAPI x::ThreadFx(LPVOID parm)
{
((x*)pamr)->neededfunc();
}
void x::launch_thread()
{
mythread = CreateThread( NULL,0,LPTHREAD_START_ROUTINE) (LPVOID)this,null,0,&dwThreadId);
}

John Fill
1c.bmp


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top