2.2.1 What is it?
1class A
2{ 3 int i;
4 protected:
5 int j;
6 public:
7 int k;
8};
9 10class B :
private A
11{ 12 public:
13 int L;
14};
15 16class C :
public B
17{ 18};
19 20void test(
void)
21{ 22 B myB;
23 24 myB.i = 0;
25 myB.j = 0;
26 myB.k = 0;
27}
Again, class B acts as a gate. However, this time, the gate is very well guarded. Although class B has access to all the
protected and public members of A, it exposes none of the member of A to the public or its descendents.
- Neither B or C can see A::i because it is private to A.
- B can see A::j and A::k because B inherits directly from A. However, both A::j and A::k are now limited as
private.
- C cannot see A::j nor A::k because they are private in class B.