I’m receiving the following warning:
warning: converting from 'void (MyClass::*)(byte)' to 'void (*)(byte)'
This is because I need to pass as argument a member function instead of an ordinary function. But the program is running correctly.
I’d like to disable this warning (Wno-bad-function-cast doesn’t work for C++) or to implement a different way to pass a member function.
No. Take this warning seriously. You should rather change your code to handle this scenario.
Pointer to member function(
void (MyClass::*)(byte)) and normal function pointer (void (*)(byte)) are entirely different. See this link. You cannot cast them just like that. It results in undefined behavior or crash.See here, how they are different:
Now you may feel that,
foo(byte)andMyClass::foo(byte)have same signature, then why their function pointers are NOT same. It’s because,MyClass::foo(byte)is internally resolved somewhat as,Now you can smell the difference between them.
Declare pointer to member function as,
You have to use this
ptrwith the object ofMyClass, such as: