lordx
asked on
Threading a Member function
I am trying to create a thread from inside a class using another class member. Here is an example of what I want to do. The function I want to thread is of type "unsigned long _stdcall A::one(LPVOID)" which would work if I didn't have the "A::" scope operator. Can I type cast this and remove the scope operator?
Or since the CreateThread function is not a member of the class A, it would violate the Data Abstraction that exists inside classes. But that should be a runtime error not a compile error, right?
class A{
one();
unsigned long _stdcall two(LPVOID);
int hThread;
HANDLE ThreadID;
};
unsigned long _stdcall A::two(LPVOID D){
//Do Some Stuff
}
void A::one(){
char buff[100];
void *data=&buff;
hThread=CreateThread (NULL, 0, two, data, 0, &ThreadID);
}
Or since the CreateThread function is not a member of the class A, it would violate the Data Abstraction that exists inside classes. But that should be a runtime error not a compile error, right?
class A{
one();
unsigned long _stdcall two(LPVOID);
int hThread;
HANDLE ThreadID;
};
unsigned long _stdcall A::two(LPVOID D){
//Do Some Stuff
}
void A::one(){
char buff[100];
void *data=&buff;
hThread=CreateThread (NULL, 0, two, data, 0, &ThreadID);
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What I usually do in this type of situation is to use a global function that's a frind of the class. Then I pass the object in as the data and then cast it to a "SurrogateThis".