Possible Duplicate:
C++: malloc : error: invalid conversion from ‘void*’ to ‘uint8_t*’
Hello,
I have this little function
Uint32 moveSprite(Uint32 interval, void *param)
{
SDL_Rect* spritePos = param;
spritePos->x++;
return interval;
}
The problem here is quite simple, I’m using codeblocks, when i save this file as a C file, it compiles with no problems, but once I save it as a C++ file, I have this error:
error: invalid conversion from 'void*' to 'SDL_Rect*'|
Does anyone have a clue on what’s the problem here?
Your code is valid C, not valid C++. You need to add an explicit casting for it to compile
Either C-style:
Or more C++-ish:
A better solution would be to change the parameter type instead if that’s possible for you. Avoid
void *whenever you can!