I'm having problems casting a function pointer. It works (no cast needed) outside a class.
Here is the signature of the function I'm calling.
Result* FancyClass::callMe(void(*functionPointer)()) It works with.
void defaultState() { // } // .. Result *result= instance.callMe(defaultState); But it does not work with
void MyClass::defaultState() { // } // .. Result *result= instance.callMe(MyClass::defaultState); I am getting this:
argument of type "void (MyClass::)()" is incompatible with parameter of type "void ()()"
How to cast this correctly?
this. Only static method can be cast this way.callMeis a library function that you have no control over, then with that signature it is impossible to call it properly with a non-static data member function. That's simply a design flaw of the library. Even as a C-style interface it must accept an additional user context pointer in order to support member function calls. The only thing you can do is call the non-static member function on a static instance of the class via a free function (or static member function).