C++ Virtual Function

virtual function is such function which is declared inside the base class and redefined by the derive class. C++ uses a virtual keyword to make a function as a virtual function. The virtual function is always defined in the base class.

The concept of polymorphism is also achieved using the virtual function. If two functions with the same name present in base and derive class then the pointer of the base class would call the functions associated only with the base class.

C++ Virtual Function Example

Output:

Leave a Comment