Virtual Functions in C++ Explained With Simple Example
A virtual function is a member function which is defined in Base class and redefined by the derived class. “virtual” keyword must be added before the function declaration to define a function virtual. These functions gets inherited by Derived class from Base class and Derived class can choose to provide it’s own definition.
A pure virtual function is a virtual function which has no definition in Base class. Pure virtual function definition is used to ensure all derived class must override the base class function definition.
Normal syntax to define virtual function is as follows:
virtual int samplefun (int x, char c);