CPolygon::width // protected access
CRectangle::width // protected access
CPolygon::set_values() // public access
CRectangle::set_values() // public access
This is because we have derived a class from the other as public, remember:
class CRectangle: public CPolygon;
this public keyword represents the minimum level of protection that the inherited members of the base class (CPolygon) must acquire in the new class (CRectangle). The minimum access level for
the inherited members can be changed by specifying protected or private instead of public.
For example, daughter is a class derived from mother that we defined thus:
class daughter: protected mother;
this would establish protected as the minimum access level for the members of daughter that it i
nherited from mother. That is, all members that were public in mother would become protected
in daughter, that would be the minimum level at which they can be inherited. Of course, this would
not restrict that daughter could have its own public members. The minimum level would only be
established for the inherited members of mother.
The most common use of an inheritance level different from public is private that serves to
completely encapsulate the base class, since, in that case, nobody except its own class will be able
to access the members of the base class from which it is derived. Anyway, in most cases classes
are derived as public.
If no access level is explicitly written private is assumed for classes created with the class
keyword and public for those created with struct.