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

argument 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.

Edited 6 Years Ago by TheGhost: n/a

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

Edited 6 Years Ago by 3bdelhakeem: n/a

Do you get this error on line 8?

yeah, the error's on line 8.

so, what should i do?

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 :)

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.

This article has been dead for over six months. Start a new discussion instead.