In C + +, there are two basic relationships between classes and classes: Composite relationships and inheritance relationships.
A composite relationship is also known as a "has a" or "has" relationship, and is manifested as a enclosing class, where one class takes an object of another class as a member variable.
An inheritance relationship is also known as a "is a" relationship or a "yes" relationship, that is, a derived class object is also a base class object.
When designing two related classes, it is important to note that not two classes have common ground and can make them an inheritance relationship. To have Class B inherit Class A, it must satisfy the proposition that what Class B represents is also the thing represented by Class A, which is logically established. For example, write a point on a plane dot:
Class cpoint{ double X, y;};
Also write a circle class ccircle. The Ccircle class has a center point, and the center of the circle is a bit on the plane, so the Ccircle class and the CPoint class seem to have common member variables. If you therefore let the Ccircle class derive from the CPoint class, use the following notation:
Class Ccircle:public cpoint{ double radius;};
is not correct. Because, "The circle is also point" this proposition is not tenable. The correct approach is to use the "has a" relationship, in which the CPoint member variable is introduced in the Ccircle class, representing the center of the circle:
Class ccircle{ CPoint Center; double radius;};
New standard C + + programming
Two relationships between classes and classes------New standard C + + programming