1. The relationship between classes and classes
Has-a,uses-a and Is-a
Has-a contains relationships that describe a class consisting of multiple "part classes". Implementing a has-a relationship is represented by a class member, that is, the data member in one class is another class that has already been defined.
Uses-a one class to use the other class partially. Define a friend or object parameter delivery implementation through the interaction of member functions between classes.
The is-a mechanism is called "inheritance." The relationship is transitive and not symmetric.
classa{ Public: voidFunca () {}intA;};//Class B has a member variable of Class A, B has A, Class B depends on Class Aclassb{ Public: voidFUNCB () {} a A;};//the member method of Class C requires the formal parameter of Class A, C use a, Class C depends on Class Aclassc{ Public: voidFUNCC (A *a) {}voidFUNCCC () {}};//Class D inherits from Class A, class D if it is inheriting Class A, Class D is Class A, Class C inherits from Class A, and the coupling is very highclassD: Publica{ Public: voidFuncd () {cout<< a <<Endl; }};
2, the basic concept of inheritance
Inheritance and derivation (1)--the relationship between classes and classes, basic concepts of inheritance