A virtual function allows derived classes to replace the implementation provided by the base class. The compiler makes sure the replacement is always called whenever the object in question is actually of the derived class, even if the object is accessed by a base pointer rather than a derived pointer. This allows algorithms in the base class to be replaced in the derived class, even if users don't know about the derived class.
The virtual function is used in the case of multiple inheritance.consider a base and two derived classes.the two derived classes has its own plus the features of base class.again if we derive one more class from these two derived classes,the new derived class will have its own plus the featuresof the base class.but it will have two copies of the main base class.to avoid this we deive the base class as virtual.
Virtual function means in order to achive runtime polymorphism and at run time compiler sud able to access the exact version of the function based on the type of object pointed to by base pointer.
virtual function is a function which is declared in the base class.and when base class inharited then this nirtual functions are redefine to fits its own needs.itis used as a form of interface