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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a thread with a class member

Status
Not open for further replies.

McBugzz

Programmer
Sep 17, 2002
90
0
0
JP
I absolutely need to create a new thread, and the starting procedure has to be a non-static class member function. Is that possible? I get "error C2664: '_beginthread' : cannot convert parameter 1 from 'void (void *)' to 'void (__cdecl *)(void *)'" which is natural because "this" pointer is also passed to all non-static members...

The method has to be non-static for two reasons: a) I may need several instances of the class in question; b) making this method static will force to make some fields static too, and static variables have a very limited scope - file.

Anybody can suggest anything?
 
1. You can't start a thread with non-static member function because of a pointer to non-static member function is NOT a pointer to an ordinal function (remember about hidden this pointer parameter, for example).
2. Static members have a class scope, they are true static vars and live from the program start upto its die...
3. You may pass a class object pointer or reference in your (static member or ordinal proxy) thread function to call this object members in the thread...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top