First: the inheritance access specifier does not change the way Derived interacts with Base , it changes the way the Derived object is treated as a world, as if it were Base .
Consider:
struct A{}; struct B: xxxx A { friend void friendly(); }; struct C: B {}; void outsider();
A very simple table: I summarize which zones A different participants can access.
xxxx public protected private B pub/prot pub/prot pub/prot friendly pub/prot pub/prot pub/prot * C pub/prot pub/prot -- outsider pub -- --
Note (*): A friend has the same rights as the object itself, not surprisingly.
A simple rule is to consider that the inheritance access specifier overrides the base class access specifiers, if they are more free.
Since nothing is less than public , this does not change anything. protected means that the public Base section becomes protected , and private means that the public and protected sections become private .
Matthieu M.
source share