The sample method below is intended to detect whether or not it has been overridden in a derived class. The error I get from MSVC implies that it is simply wrong to try to get the function pointer to a "bound" member, but I see no logical reason why this should be a problem (after all, it will be in this->vtable). Is there any non-hacky way of fixing this code?
class MyClass
{
public:
typedef void (MyClass::*MethodPtr)();
virtual void Method()
{
MethodPtr a = &MyClass::Method; // legal
MethodPtr b = &Method; // <<< error C2276: ‘&’ : illegal operation on bound member function expression
if (a == b) // this method has not been overridden?
throw “Not overridden”;
}
};