A virtual function is a function member of a class, declared using the "virtual" keyword. Virtual function can be used to override the properties of a function.it is normally used in inheritance. it is part of polymorphism.
When derived class overrides the base class method by redefining the same function, then if client wants to access redefined the method from derived class through a pointer from base class object, then you must define this function in base class as virtual function.
When derived class overrides the base class method by redefining the same function, then if client wants to access redefined the method from derived class through a pointer from base class object, then you must define this function in base class as virtual function.