C++ virtual function
A virtual function is a member function in the base class that is overridden by a derived class. It allows the function to be redefined in the derived class so that the most appropriate function is called for the object.
- Declare the base class with a virtual function.
- Define the virtual function in the base class.
- Declare the derived class that overrides the virtual function.
- Define the overridden virtual function in the derived class.