Key points: inheritance, multiple inheritance, What's inherited
//What is inheritance#include <iostream>using namespacestd;classPolygon {protected: intwidth, height; Public: voidSet_values (intAintb) {width=a; height=b;} };classRectangle: PublicPolygon {//rectangle inherits from Polygon Note:::. Public details publicly represents the highest permission a subclass can get from a base class, and if there is a contradiction to private, other classes that should be non-fee-inheriting can also get exposed members from the base class Public: intArea () {returnWidth *height;} };classTriangle: PublicPolygon {//triangles inherit from polygon triangles belong to polygon derived classes inherit public from the base class as public Public: intArea () {returnWidth * Height/2; } }; intMain () {Rectangle rect; Triangle Trgl; Rect.set_values (4,5); Trgl.set_values (4,5); cout<< Rect.area () <<'\ n'; cout<< Trgl.area () <<'\ n'; return 0;}
A rectangle is a polygon with four sides of the rectangle
A triangle is a polygon, a triangle has three edge attributes, many of which are subclasses, with fewer attributes for the base class
Multiple inheritance, inherited base class without cross-commonality
Dog with skin four legs with eyes and mouth
A fish with a skin, a mouth, and a fish fin. The top three can be combined as a base class, or it can be separated as a feature of the last of the three base classes as subclasses
The constructor of the subclass is automatically dispatched as the constructor destructor of the parent class
C + + Inheritance