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!

thread & class

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
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 spew out garbage messages like:
&quot;error C2440: 'type cast' : cannot convert from '' to 'unsigned long (__stdcall *)(void *)'&quot;

please help me

dams
 
It seems this problem has nothing to do with threads.
In C++ there is a difference in type between

void MyClass::Function()
{
// Do something
}

and

void Function1()
{
// Do something else
}


The difference being that the second function can be used whenever a function accepting no parameters and returnig nothing is required, and the first one can be used whenever a function, member of the class MyClass, accepting no parameters and returnig nothing is required.

The message you get is not garbage, but reflects a syntax error. It seems a function accepting no paramenters and returning an unsigned long is required.

Your function is member of a class and does not return an unsigned long, so there are two reasons why it cannot be used as a parameter.

However you could overload the operator() in order to make your class &quot;appear&quot; an ordinary function.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top