To me it looks perfectly safe to cast a void(Derived::*)()
to a void(Base::*)()
, like in this code:
#include
#incl
No, it's potentially dangerous.
A derived class function can use all the derived class properties of *this
. A pointer to base class function can be called on any base class instance, even those that are not of the derived type.
Accessing the derived class properties of an instance that isn't a derived class isn't going to work so casting a pointer to derived class function to a pointer to base class pointer is correctly not allowed.
On the other hand, casting a pointer to base class function to a pointer to derived class function is safe and legal.