C++ Threading: Referencing a member of a class instance

Associate
Joined
22 Jul 2004
Posts
230
Location
Nottingham, UK
I'm using a custom library to start a thread.
I want the threaded function to be a member of an instance of a class:
Code:
class A{
	public:
		void ThreadStart(void *);
};

A* a;

int main(){
	a = new A();
	
	CustomLib::StartAThread(a->ThreadStart,"",0); // Error Here
}

The error is:
Code:
error C3867: 'A::ThreadStart': function call missing argument list; use '&A::ThreadStart' to create a pointer to member.

I can work around it using this, but it isn't really the way i want todo it.
Code:
class A{
	public:
		void ThreadStart(void *);
};

A* a;

int main(){
	CustomLib::StartAThread(Start,"",0); // References a static function instead.
}

void Start(void *){
	a = new A();
	a->ThreadStart();
}
 
Back
Top Bottom