Polymorphism is implemented using virtual functions, the virtual function is used to inherit the hierarchy of the parent class and subclass, in addition to the base class and the subclass of the function name must be the same, the same parameter type, number and order of the same, that is, the parent class and the subclass of the virtual function can not just name overloading, but its declaration to be identical. Otherwise, no polymorphism can occur, even if you mark virtual.
An exception to the case, the return type exception.
VOID fn (int);
INT fn (int);
If the virtual function of the parent class and the subclass is as different as the two functions above, it can be polymorphic.
Some limitations of virtual functions:
1. Only member functions of a class can be declared as virtual functions
Because virtual functions only apply to class objects that have an inheritance relationship, ordinary functions cannot be declared as virtual functions.
2. A static member function cannot be a virtual function
Because static member functions are not bound by an object, even if the form is bundled, there is actually no information about the object, only the class information.
3. An inline function cannot be a virtual function
Because an inline function cannot dynamically determine its position in the run.
4. A constructor cannot be a virtual function
Because the object is still an amorphous virgin territory when constructed, the object can become a veritable object of a class only after the construction is complete.
5 destructors can be virtual functions and are typically declared as virtual functions.
1