I know this is pretty much pure evil... But would it work? (assuming that "instance" is of the correct type for the function)
class DummyClass { };
typedef bool (DummyClass::*tHandler)(const Data& d);
template <class T> inline static tHandler CastHandler(bool (T::*hfunc)(const Data& d))
{
return reinterpret_cast<tHandler>(hfunc);
}
inline static bool CallHandler(void* instance, tHandler hfunc, const Data& d)
{
return ((*reinterpret_cast<DummyClass*>(instance)).*hfunc)(d);
}
The intended outcome is calling any function in the form of tHandler from any class. The rest of the code would simply hold some tHandler objects and use them through those two functions. It would also ensure that "instance" is of the same type as the function pointer was taken from.
I mean, a function of the form:
typedef bool (DummyClass::*tHandler)(const Data& d);
Should still be equivilent to (and callable like) a function of the form
typedef bool (SomeOtherClass::*tHandler)(const Data& d);
Shouldn't it?
Would I be right in suggesting that the actual class type that is associated with the function pointer's type dosn't actually do anything useful besides type-safety?