class A {public: A() { n = 0; } void add( int i ) { n = n + i; } virtual int val() { return n; } protected:
ancestor private would deny access to D
int n; }; class D : public A {public: D() : A() { } int val() { return n 2; } };
descendant
Allowing descendants full access to the instance variables defined by ancestors, however, increases the dependency on the actual implementation of these ancestors, with the risk of a total collapse when the implementation of an ancestor changes.