Complete the code to declare a base class function that can be overridden.
class Base { public: virtual void [1]() { std::cout << "Base function" << std::endl; } };
The function name display is used in the base class and will be overridden in the derived class.
Complete the code to override the base class function in the derived class.
class Derived : public Base { public: void [1]() override { std::cout << "Derived function" << std::endl; } };
override keyword.The derived class overrides the display function from the base class.
Fix the error in the base class function declaration to allow overriding.
class Base { public: virtual void [1]() { std::cout << "Base function" << std::endl; } };
The base class function must be declared virtual to allow overriding, but here the blank is the function name which must be display to match derived class.
Fill both blanks to complete the derived class overriding the base class function.
class Derived : public Base { public: [1] [2]() override { std::cout << "Derived override" << std::endl; } };
The function must have the same return type void and the same name display as in the base class to override it.
Fill all three blanks to call the overridden function through a base class pointer.
Base* ptr = new Derived(); ptr->[1](); delete [2]; [3] = nullptr;
We call the overridden function display through the base class pointer ptr, then delete and nullify the pointer.