Complete the code to declare a pure virtual function in a C++ class.
class Shape { public: virtual void draw() [1]; };
= 0 and just ending with a semicolon.In C++, a pure virtual function is declared by assigning = 0 at the end of the function declaration.
Complete the code to override the pure virtual function in the derived class.
class Circle : public Shape { public: void draw() [1] { // drawing code } };
override keyword.When overriding a virtual function, use the same signature and add override to indicate it overrides a base class method.
Fix the error in the code to prevent instantiation of the abstract class.
Shape s[1];You cannot create an object of an abstract class. The error is trying to instantiate Shape with parentheses. To fix, remove the instantiation or use a pointer/reference.
Fill both blanks to declare an interface-like class with a pure virtual destructor.
class Interface { public: virtual ~Interface() [1]; virtual void execute() [2]; };
To make a class interface-like, declare all functions, including the destructor, as pure virtual by using = 0.
Fill all three blanks to implement a derived class overriding interface methods correctly.
class Impl : public Interface { public: ~Impl() [1] override [2] { // destructor code } void execute() [3] override { // execution code } };
Destructor and methods must have matching signatures and bodies. Use () for parameters and {} for function bodies.