This allows us to create an object derived from another one, so that it may include some of the other's members plus its own ones. For example, we are going to suppose that we want to declare a series of classes that describe polygons like our CRectangle , or like CTriangle . This could be represented in the world of classes with a class CPolygon from which we would derive the two referred ones, CRectangle and CTriangle . The class CPolygon would contain members that are common for all polygons. And CRectangle and CTriangle would be its derived classes.
Classes derived from others inherit all the visible members of the base class.
That means that if a base class includes a member A and we derive it to another class with another member called B , the derived class will contain both A and B . The protected specifier is similar to private , its only difference indeed occurs when deriving classes. When we derive a class, protected members of the base class can be used by other members of the derived class, nevertheless private member cannot. As we wanted that width and height have the ability to be manipulated by members of its derived classes CRectangle and CTriangle and not only by members of CPolygon we have used the protected access instead of private . That is, all members that were public in mother would become protected in daughter , that would be the minimum level which they can be inherited.