Friday, March 18, 2011

error: invalid conversion from void (*)(void*, void*) to void*

If you get an error like "{error: invalid conversion from void (*)(void*, void*) to void*", you need to typedef your function pointer according the function being pointed to.

Consequently, use this typedefed variable in the function call instead of "void*" or something else.

In my case,
I had to call my function having the signature as

void fun(void*, void*)

My typedef would look like

typedef void (className::*Method) (void*, void*);
OR
typedef void (*Method) (void*, void*);
whichever works for you.
For the first usage you will need a forward decalartion of your class, like
class className;

In the function which takes this function pointer, use the Method variable instead of "void *" or anything else.

void callingFunc(Method function);

Hope the clarifies to some extent

No comments:

Post a Comment