//1. The core idea of object-oriented programming is data abstraction, inheritance and dynamic binding. //by using data abstraction, we can separate the interface and implementation of the class//with inheritance, you can define similar types and model their similar relationships//with dynamic binding, you can ignore the differences of similar types to some extent, and use their objects in a uniform way. //2. For some functions, the base class expects its derived classes to define their own versions individually, at which point the base class declares these functions as virtual functions. //when a virtual function is called with a reference or pointer to a base class, dynamic binding occurs: Call the base class or the virtual function of the derived class based on the object type pointed to by the pointer or reference. //a base class typically defines a virtual destructor to facilitate the normal destruction of an object//A non-static function other than any constructor can be a virtual function. A virtual function in a base class, implicitly in a derived class, is also a virtual function. //if the member function is not declared as a virtual function, its parsing process occurs at compile time and not at runtime. //each class controls the initialization of its own members, and derived classes must also use the constructor of the base class to initialize its base class part//3. It is important to bind a pointer or reference of a base class to a derived class object: When you use a pointer or reference to a base class type, it is not really clear what type of object it is bound to. //The conversion of a derived class to a base class is valid only for pointers and reference types, and there is no such conversion between the derived class type and the base class type. //4. Smart pointer classes also support the conversion of derived classes to base classes, which means that pointers to objects of derived classes can be stored inside a smart pointer of a base class. //5. A derived class if you want to overwrite rather than hide an inherited virtual function, its formal parameter type must be exactly the same as the virtual function being overridden. //Similarly, their return types must also be consistent. There is one exception to this rule: when this function returns a pointer or reference to its class type, and the child class is accessible when it is converted to the parent class type, they can return their class type. //6. Virtual functions can also have default arguments, but if a function call uses a default argument, the argument value is determined by the static type of the call. Therefore, virtual functions are best used without default arguments, or in subclasses and base classes using the same default arguments. //by using the scope operator, you can implement a call to a virtual function without dynamic binding. //7. Abstract base class://A : Unlike ordinary virtual functions, a pure virtual function can be undefined, and a virtual function can be declared as pure virtual function by writing =0 in the position of the function body, and =0 can only appear in the inner virtual function declaration of the class. //B: You can also provide a definition for a pure virtual function, but it must be outside of the class. //C: You cannot define an object of an abstract base class, and this derived class cannot define an object when the derived class of the abstract base class does not overwrite a pure virtual function. //8. The constructor of a derived class initializes only its immediate base class. Each class controls the initialization of its objects. //9. Accessibility of derived classes to base class conversions://A: User code can use a derived class to convert to a base class only if D is a public inheritance B. //B: Regardless of whether D inherits B,d in any way member functions and friends can use derived classes to convert to the base class. //C: If D inherits B in a public or protected manner, the members and friends of the derived class of Class D can use the D-to-B type conversion. //Summary: For a node in your code: if the public member of the base class is accessible, then the conversion of the derived class to the base class is also available, and vice versa. //10. Just as a friend relationship cannot be communicated, a friend relationship cannot be inherited. A friend of a base class does not have a special access to a derived class member, and similarly, a friend of a derived class cannot access the members of the base class at will. //11. Derived classes can provide a using declaration for those names that can be accessed, in such a way as to change the access rights of the declared name (depending on the location of the using declaration). classCA {protected:intvalue;};classCb: PublicCA { Public:usingCa::value;};//The access rights of value in the CB class are public//the only difference between 12.struct and class is that the default member access specifier differs from the default derived access specifier, which is both public and private. //13. Each class defines its own scope. When an inheritance relationship exists, the scope of the derived class is nested within the scope of its base class. When a name cannot be resolved in the scope of a derived class, the compiler will look in the base class scope of its outer layer. //it is because of the foregoing that the members of the base class can be used in a derived class as if they were members of their own. //The static type of an object, pointer, and reference determines which members of the object are visible. Even though static types and dynamic types may be inconsistent, we can use which members are still determined by their static type. //14. Like other scopes, derived classes can reuse names defined in their direct or indirect base classes, where they are hidden, members of derived classes will hide base class members with the same name, and hidden members can be accessed through scope operators. //because of the hidden rules above, a derived class can overwrite the 0 or all versions of the overloaded virtual functions of its base class, otherwise it will be hidden. This will appear and cumbersome. //a good workaround for the above problem is to provide an overloaded member with a using declaration statement so that we do not have to overwrite each overloaded version in the base class. At this point, the derived class only needs to define its special function statement. classCA { Public: Virtual voidFun () {printf ("A_0");} Virtual voidFunint) {printf ("a_1");} Virtual voidFunChar*) {printf ("a_2");}};classCb: PublicCA { Public: usingCa::fun;//causes all the fun functions in the base class to be added to the scope of the derived class. voidFuninti) {printf ("b_1");}//redefine a specific virtual function in a derived class. }; //15. The most direct effect of inheritance relationships on base-class copy control is that base classes should typically define a virtual destructor to properly dispose of objects. //A synthetic copy control member of a base class or derived class initializes, assigns, and destroys the members of the class itself, and the members of these compositions are also responsible for manipulating the direct base class portion of an object using the corresponding operation in the direct base class. //when an object of a derived class is destroyed, the destructor of the direct base class is automatically called (up until the top of the inheritance), but the construction, movement, and so on of the derived class object requires its own part of the base class to be considered. //In the actual programming process, if there is no default, copy, move constructor in the base class, then the derived class does not generally define the corresponding operation, because the base class part of the derived class will not be able to operate correctly.
16. When we initialize or assign a derived class object to its base class object, only the base class part of the derived class object is copied, moved, assigned, and its derived class part is ignored.
17.
A (base class) B (derived class)
Public inheritance of public members public members
Protecting member Protection members
Private members are not visible
Protecting members from inheriting public members
Protecting member Protection members
Private members are not visible
Private inheriting public member private members
Protect member Private members
Private members are not visible
Generally, public inheritance is a relationship of is a, and private inheritance is the relationship of has a
C++primer the 15th chapter