| Share this post! | Vote this! |
|
A key feature of C++ classes is inheritance. Inheritance allows to
create classes which are derived from other classes, so that they
automatically include some of its “parent’s” members, plus its own. 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.
They have certain common properties, such as both can be described by
means of only two sides: height and base. This could be represented in
the world of classes with a class CPolygon from which we would derive the two other ones: CRectangle and CTriangle.
The class CPolygon would contain members that are common for both types of polygon. In our case: width and height. And CRectangle and CTriangle would be its derived classes, with specific features that are different from one type of polygon to the other. more...
The class CPolygon would contain members that are common for both types of polygon. In our case: width and height. And CRectangle and CTriangle would be its derived classes, with specific features that are different from one type of polygon to the other. more...




0 comments:
Post a Comment