virtual function

A virtual function is a member function that helps to redefine the implementation in the derived class. When two functions of the same name are present in the base and derived class, the base class function will be declared with the keyword virtual. Hence both classes can have the same function name with a different implementation. During runtime, it determines which function to call based on the object pointer it points to.
```
#include <iostream>
using namespace std;

class Base {
public:
    virtual void func() { cout << "Base:func()" << endl; }
    Base() { func(); }  // Base:func()
    void call() { func(); }
};

class Sub : public Base {
public:
    void func() { cout << "Sub:func()" << endl; }
    Sub() { func(); } // Sub:func()
    void call() { func(); }
};

int main() {
    Base * b = new Sub();
    
    b->Base::call(); // Sub:func()
    b->call();  //  Sub:func()
    delete b;
    
    return 0;
}
```