I am trying to convert a C
code to C++
. In my .c file I've definitions like this:
void services(void);
void transfers(void);
Further more, a thread will initialize the above two like this:
_beginthread((void*) services,0,NULL);
_beginthread((void*) transfers,0,NULL);
When I try to compile, I got the following error at both the places above like this:
Conversion from void* to pointer to non-void required an Explicit cast: Cannot convert parameter 1 from void* to void(_cdecl*)(void*)
I am confused about this, hope you guys make it clear for me :-)
Try:
What you were doing was explicitly casting the function pointer to a non-function pointer type (
void *
). This was OK. But the_beginthread
function expects as its first parameter a function pointer of the correct type mentioned in the error message. So you need to fix your cast.If you're about to downvote this answer, I'd appreciate to know the reason why. I know it would be much better if user2754070 wanted to change the prototype of
services
(see my comments below). However, what I'm suggesting works (the answer was accepted) and, as far as I know, it is safe and standard practice in C libraries spawning threads. If you think it's not, please explain why and I'll consider deleting the answer.