What are virtual functions? How do they work?
virtual functions
800
10-Jul-2018
Prakash nidhi Verma
10-Jul-2018Virtual Function :
virtual function is an implementation of runtime polymorphism. When we declare a pointer of the parent class either assign the address of the base class object irrespective of that when we call the function by using that pointer the it is always call the base class member function even if we assign the address off child class object. What actually happen that when we declare a base class pointer it is associated with the base class member function at the time of compilation by the compiler So, it always call the base class member function .
Example :
To remove this problem we declare the base class member function as virtual by using virtual keyword.