Virtual Function

Function is a virtual function when the virtual keyword is added in the beginning of function declaration.virtual void display();virtual keyword is required in declaration. In function definition, virtual keyword is not required. When you want to override(redefine) the function in derived class, then virtual function is required. This means virtual function works only when inheritance is involved. Let us understand with the help of an example. class shape {public: virtual void draw() {} virtual void func() {}};class rectangle: public shape {public: void draw() { cout << “Draw rectangle” << endl;…