Virtual
Pure Virtual
SO
GFG
A pure virtual function is implemented by classes which are derived from a Abstract class.
Virtual Function
Take note that virtual functions work on object pointers (and references), but not on regular objects.
When you refer to a derived class object using a pointer or a reference to the base class, you can call a virtual function for that object and execute the derived class’s version of the function.
For non-virtual function, the compiler selects the function that will be invoked at compiled-time (known as static binding).
For virtual functions, the selection is delayed until the runtime. The function selected depends on the actual type that invokes the function (known as dynamic binding or late binding).
Virtual Class
Using Polymorphism:
- Create instances of concrete subclass.
- Declare superclass (possibly abstract) pointers (or references).
- Aim the superclass pointers to the subclass instances.
- Invoke virtual function, with implementation provided by subclass.