Modifying access levels in inheritance

When declaring a sub-class, it is possible to modify the access levels of the attributes in the parent class, by including a specifier before the parent class name. If no modifier is given, private is assumed for a class.

class new_linkage: private mylinkage {
   int val;
};

The specifier private here makes the attributes of mylinkage inherited by new_linkage objects appear as private members, i.e. no previously public or protected attributes of mylinkage can be accessed directly outside this new class. The following table summarises this.


Effects of derivation access control on access in a derived class

Access in base class
private protected public
Modifier specified
private Inaccessible private private
protected Inaccessible protected protected
public Inaccessible protected public


Next note in series

Back to index