It is right. The relevant part of the Standard is given above, but here is the rationale for what it costs.
The protected semantics in C ++ means that "this element can be accessed from the methods of this class or any derived classes, but only when the dynamic type of the object being accessed is guaranteed to be the same as or obtained from type *this ".
The last bit may not be quite obvious, here is an example:
class Base { protected: int X; }; class Derived : public Base { void Foo(Base* b, Derived* d) { this->X = 123;
This is by design - the idea is that Derived2 can have its own opinion on how its protected members should be handled (what are the invariants, etc.), and this should be strictly between him and his base class (and its derivatives classes, but only if he decided not to hide this field by making it private ). Access to the cross hierarchy contradicts this model, since it actually means that the base class pre-decides the entire hierarchy; for very abstract classes on top of deep hierarchies this may not be desirable.
Now back to your specific problem - by now this should be pretty obvious. Once you get a pointer to a member function, you can call the function that this pointer points to with any recipient of the appropriate type. For a protected method of a base class, this means that if you could get a pointer to it that would be introduced into the base class (and not to your own class), you could call it by passing it a pointer to a type other than your class (or derived from it) in violation of the secure access rules described above. Therefore, you are not allowed to do this.
source share