Virtual Functions
A virtual function (also known as virtual methods) is a member function that is declared within a
base class and is re-defined (overridden) by a derived class. 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 method.
Virtual functions ensure that the correct function is called for an object, regardless of the
type of reference (or pointer) used for the function call.
They are mainly used to achieve Runtime polymorphism.
Functions are declared with a virtual keyword in a base class.
Virtual destructors in c++
Virtual Destructor in C++ is a member function that frees up the memory allocated by the object of a
child class or derived class when it is removed from the memory using the parent class pointer
object. Virtual destructor in C++ is mainly responsible for resolving the memory leak problem.