954,496 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

threads of an Object?

i want to make an Object Test to control many threads.

Test.cpp

class Test{
	public:
		Test();
		void exampleThread(void*);
};

Test::Test(){
	_beginthread(exampleThread, 0, 0);
}

void Test::exampleThread(void* ptr){
	...
}


i get the errorargument of type `void (Test:: )(void*)' does not match `void (*) (void*)'

what must i write so that i can make an Object control many threads?

thanks.

TheGhost
Newbie Poster
23 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
 

Do you get this error on line 8?

If you get this error on line 8, replace this line:

void exampleThread(void*);


by this one

void (*exampleThread)(void*);


Regards,,,
Kimo

kim00000
Junior Poster in Training
93 posts since Oct 2009
Reputation Points: 12
Solved Threads: 11
 
Do you get this error on line 8?

yeah, the error's on line 8.

so, what should i do?

TheGhost
Newbie Poster
23 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
 

I think the _beginthread takes a
void(*Somevoid)(void *)
as the first argument...

and you passed a
void Somevoid(void *) to it, so that's the reason

Regards,,,
Kimo :)

kim00000
Junior Poster in Training
93 posts since Oct 2009
Reputation Points: 12
Solved Threads: 11
 

i want to make an Object Test to control many threads.

Test.cpp

class Test{
	public:
		Test();
		void exampleThread(void*);
};

Test::Test(){
	_beginthread(exampleThread, 0, 0);
}

void Test::exampleThread(void* ptr){
	...
}

i get the error

what must i write so that i can make an Object control many threads?

thanks.

The short answer is you can't pass a non-static member function to _beginthread . The reason is that a member function takes a this pointer as a hidden parameter. Therefore the signature doesn't match. And of course there's no instance of Test that _beginthread knows about and could call exampleTest with.

For a solution read this . It talks about CreateThread ; I am sure you could adopt it to _beginthread as well.

nezachem
Posting Shark
903 posts since Dec 2009
Reputation Points: 719
Solved Threads: 194
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You