3 Fine tuning exposure

You can fine tune the exposure from inheritance down to individual members. Listing 4 demonstrates how to control the exposure of individual members.


Listing 4:individualmember
 
1class A 
2{ 
3  protected
4    int i; 
5  public
6    int j; 
7}
8 
9class B : private A 
10{ 
11  public
12    A::i; 
13}
14 
15class C : public A 
16{ 
17  private
18    A::j; 
19};

In this example, class B hides everything that it inherits from class A. However, it reexposes member i of class A as a public member of B.

Class C reexposes everything that it inherits from class A, to the degree that class A permits. However, it hides member j from class A from subclasses and the public.

This method reexposes or hides certain members as exceptions to the class inheritance exposure restriction. As a result, a subclass has very fine control over what members to hide from everyone (private), hide from the public (protected) or reexpose to everyone (public).