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.

Recommended Answers

All 4 Replies

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.