I\'m surprised that the code below compiles.
It seems that a class befriended to the (publicly inherited) base class can access a member of the base class provided an in
While there already are good answers I think some images would help here a bit too.
This is an abstraction of your B
class. F
has access to all its members.
When you now instantiate a D
object it looks like this
It still is a B object but also a D object. It extends B
so to speak. F
can still access the part from B because it's still there but not from D
.
Please note that these abstractions do not really display the layout in memory and explain overriding etc. But they are just for the sake of this question.