Complete the code to declare a virtual function named display in the base class.
class Base { public: virtual void [1]() { std::cout << "Base display" << std::endl; } };
The virtual function must be named display as declared in the base class.
Complete the code to override the virtual function display in the derived class.
class Derived : public Base { public: void [1]() override { std::cout << "Derived display" << std::endl; } };
override keyword (though optional, it helps).The derived class overrides the base class virtual function named display.
Fix the error in the code to call the derived class display function through a base class pointer.
Base* ptr = new Derived();
ptr->[1]();Calling display on the base class pointer invokes the derived class version because display is virtual.
Fill both blanks to declare a pure virtual function show in the base class and override it in the derived class.
class Base { public: virtual void [1]() [2]; };
A pure virtual function is declared with = 0 and must be overridden in derived classes.
Fill all three blanks to implement the derived class overriding the pure virtual function show and calling it.
class Derived : public Base { public: void [1]() override [2]; }; int main() { Base* obj = new Derived(); obj->[3](); delete obj; return 0; }
The derived class overrides show with an empty body {} and calls show() through the base pointer.