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
D
is a B
when public inheritance is used. So accessing b_var
is still perfectly legal.
You would get an error, however, if you attempt to access d_var
, since the friendship itself is not inherited, as you seem to be aware.
Inheritance always makes all members of the base be members of the derived. Access specifiers only affect where an identifier is visible. That's why accessing a private member illegally produces a different error to accessing an identifier that doesn't exist.