I. c ++ inheritance
1. class inheritance is a mechanism provided in object-oriented programming. It allows programmers to define more specific and detailed classes on the basis of saving the features of the original classes. (Can be associated with reality: parents and children)
2. In C ++ class inheritance, a derived class can be derived from one base class or multiple base classes. Inheritance derived from a base class is called single inheritance. Inheritance derived from multiple base classes is called multi-inheritance.
3. class inheritance methods in C ++ include public, protected, and private.
4. Note: If the keyword of the inheritance mode is not displayed, the default value of the system is private ).
Ii. Access Control
The following describes "Access Control ". The "access" here comes from two aspects:
1. The new member in the derived class accesses the inherited member from the base class;
2. The object of the derived class accesses the inherited members of the base class.
(1) Public (Public inheritance)
The public members of the base class and the access attributes of the protected members remain unchanged in the derived class, while private members of the base class cannot access the base class directly.
1. Add a member to a derived class
You can directly access the public and protected members inherited from the base class)
2. Object of the derived class
Only public members inherited from the base class can be accessed directly)
(2) Protected)
Both the public and protected members of the base class appear in the derived class as protected members, and Private Members of the base class cannot directly access the base class.
1. Add a member to a derived class
You can directly access the public and protected members inherited from the base class)
2. Object of the derived class
You cannot directly access any type of members of the base class.
(3) Private (private inheritance)
Both the public and protected members of the base class appear in the derived class as private members, and the Private Members of the base class cannot be directly accessed.
1. Add a member to a derived class
You can directly access the public and protected members inherited from the base class)
2. Object of the derived class
You cannot directly access any type of members of the base class.