I am writing a delegate class for educational purposes and have run into a small problem. The delegate should be able to call not only functions, but also member methods, which means that I need to save a pointer to a method:
void (classname::*methodPtr)(...);
And I need to store pointers to methods from different classes and with different lists of arguments. At first I just wanted to cast a pointer to the void * method, but the compiler dies with an invalid cast error. It turns out that sizeof (methodPtr) == 8 (the 32-bit system is here), but it also fails on unsigned long long (the same compiler error - invalid cast). How to save a universal method pointer?
I know this is not safe. I have other security mechanisms, just focus on my question.
source
share