Before you understand this concept, you need to understand a few concepts. Pure virtual function, virtual function, non-virtual function
Pure virtual functions: Classes declared as pure virtual functions must be used as base classes, classes containing pure virtual functions are called abstract classes, and abstract classes cannot instantiate objects. Therefore, pure virtual functions are generally used to declare interfaces. Its derived class must implement this function. Pure virtual functions can have function implementations in the base class, or they may not. The reason for declaring pure virtual functions is that the base class is often inappropriate for instantiation, such as the draw method in a shape class. Must be a pure virtual function, because he is not of any shape.
virtual function: A function declared in the base class as vitual and redefined in one or more derived classes. Virtual functions are used to provide a uniform name for a class of operations. Generally declared as virtual function is to implement polymorphism: Use the base class pointer to a derived class object, call the base class and the derived class with the same name function, call the method in the derived class (the premise vitual function is definitely implemented).
Non-virtual functions: General member functions, no virtual modifications. The derived class inherits the function interface and a mandatory implementation.
With these concepts, it is now explained that interface inheritance and implementation inheritance
Interface inheritance: Derived classes inherit only the function interface, which is the declaration. Implementing inheritance: Derived classes inherit both the interface and the implementation of the function.
Summary: When designing the class, follow the following points
- Pure virtual function: A function that requires a derived class to implement has no specific meaning in the base class.
- Virtual Functions: Inherited classes must contain interfaces that can be implemented either by themselves or not, and by the implementation of the base class.
- Non-virtual functions: An interface that inherits a class must function, and must be implemented using a base class.
From for notes (Wiz)
interface inheritance and implementation inheritance