Polymorphism in C ++ Learning (several characteristics of polymorphism)
1. the virtual function feature can be inherited. When the function defined in the subclass is the same as the virtual function declared in the parent class (the same parameter with the same name returns the same value), this function is also a virtual function; when the parent class Pointer Points to the subclass object, when the pointer calls this function with the same name, it will call the subclass function, which is a polymorphism;
2. The virtual destructor aims to avoid Memory leakage when the parent class pointer is used to release subclass objects;
3. The implementation of polymorphism in c ++ is implemented through the virtual function table;
4. Each class has only one virtual function table, and all the objects in this class share the same virtual function table;
5. The pointers in the two virtual function tables may point to the same function (for details, see the blog on the virtual function table );
6. When the class only contains virtual destructor, this class will also generate a virtual function table;
7. polymorphism-specific syntax refers to the use of a parent class pointer to point to a subclass object, and this pointer can be used to call the subclass method;
8. inheritance is the basis for producing polymorphism, and there is no polymorphism without inheritance.
9. The core of polymorphism syntax is the virtual keyword. You must use virtual to establish polymorphism between multiple classes.