1. Virtual functions and pure virtual functions can be defined in the same class, classes containing pure virtual functions are called abstract classes, and classes that contain only virtual functions (class) cannot be called abstract classes.
2. Virtual functions can be used directly, or the Quilt Class (sub Class) overloads are later called in polymorphic form, whereas pure virtual functions must be implemented in subclasses (sub Class) in order to be used, because pure virtual functions are only declared and not defined in the base class.
3. Virtual and pure virtual functions can be overloaded in subclasses (sub Class) and called in polymorphic form.
4. Virtual functions and pure virtual functions usually exist in the abstract base class (abstract base CLASS-ABC) and are inherited subclasses overloaded to provide a uniform interface.
5. Virtual function definition form: Virtual {method Body}
The definition of pure virtual function: virtual {} = 0;
There cannot be a static identifier in the definition of a virtual function or a pure virtual function, for the simple reason that the static modified function requires a prior bind at compile time, but the virtual function is dynamically bound (run-time bind) and is modified by both the function lifecycle (Life recycle ) is not the same.
6. The virtual function must be implemented, if not implemented, the compiler will give an error:
Error lnk****: unresolved external symbol "Public:virtual void __thiscall
Classname::virtualfunctionname (void) "
7. For virtual functions, both the parent and child classes have their own versions. Dynamically bound when called by polymorphic mode.
8. A subclass of a pure virtual function is implemented, and the virtual function is programmed in the subclass, and the subclass of the subclass, that is, the grandson class can override the virtual function and bind dynamically when called by the Polymorphic method.
9. Virtual functions are the mechanisms used to implement polymorphism (polymorphism) in C + +. The core idea is to access the functions defined by the derived class through the base class
10. Polymorphism refers to different implementation actions when the same object receives different messages or different objects receive the same message. C + + supports two kinds of polymorphism: compile-time polymorphism, run-time polymorphism.
A. Compile-time polymorphism: using overloaded functions
B Run-time polymorphism: implemented by virtual functions.
11. If a class contains pure virtual functions, any statements attempting to instantiate the class will result in an error, because the abstract base class (ABC) cannot be called directly. You must invoke a method of its subclass after the class inherits the overload, as required.
Polymorphism, virtual function, pure virtual function