Using the public inheritance base class, you can divide the inherited results into two types:Function interface inheritanceAndFunction implementation inheritance.
The purpose of declaring a pure function is to make the derived class inherit only the function interface. Pure virtual function has two outstanding features:
They must be re-declared by any specific class that "inherits them", and they are generally not defined in abstract classes.
The purpose of declaring a non-pure virtual function is to let the derived class inherit the interface and default Implementation of the function.
The purpose of declaring a non-virtual function is to make the derived class inherit the function interface and a mandatory implementation.
When designing a class, declare a member function and select it with caution. Declarations of different types mean things with different fundamental meanings.
The following are common mistakes made by inexperienced designers:
1. Declare all functions as non-virtual functions. This is equivalent to a derived class that inherits the function interface and mandatory implementation, so that the derived class does not have the space for special work.
This is especially true for non-virtual destructor.
However, when designing a class that is not intended as the base class, all its member functions should be declared as non-virtual.
2. Declare all member functions as virtual. Sometimes this is correct, but sometimes some functions should not be redefined in the derived class,
These functions represent immutability in the inheritance system. Therefore, if the immutability of the class body prevails over the specicity, the function sound must be non-virtual.
Inspiration: when carrying out Object-oriented Inheritance, the design of the class body is crucial. A good design of the class body and its inheritance system facilitates the implementation, protection, and expansion of the system.
Therefore, when declaring a member function, pay attention to the role and purpose of the class body, so as to select a reasonable declaration method.
References: Objective C ++