In this answer to the question \"Why can\'t my object access protected members of another object defined in common base class?\", one can read:
Y
The rule in [class.access.base] is:
A member
m
is accessible at the point R when named in classN
if [...]
m
as a member ofN
is protected, and R occurs in a member or friend of classN
, or in a member of a classP
derived fromN
, wherem
as a member ofP
ispublic
,private
, orprotected
There's a lot of letters in there. But there are basically two conditions:
R
is in a member or friend of the class. This handles the d.prot
example - we are in a member of Derived
while accessing a protected member of Derived
.R
is in a member of a derived class and the member being accessed is a member of the derived class instance. This handles the b.prot
example - we are in a member of a derived class, but prot
is not a member of the derived class. In other words, Derived
can access Base
's protected members - but only in the case that it is accessing its own subobject's protected members. It cannot access other Base
object's protected members. This makes sense when you consider that this other Base
could easily be SomeOtherDerived
, in which case that's just another unrelated object to us that we have no special access privileges to.