Complete the code to declare an abstract class with a pure virtual function.
class Shape { public: virtual void draw() = [1]; };
In C++, a pure virtual function is declared by assigning 0 to it. This makes the class abstract.
Complete the code to create a pointer to the abstract class and assign it to a derived class object.
Shape* shape = new [1]();You cannot create an object of an abstract class directly, but you can create a pointer to it and assign it to a derived class object like Circle.
Fix the error in the code by completing the missing keyword to enforce abstraction.
[1] Shape { public: virtual void display() = 0; };
In C++, classes are declared with the keyword 'class'. There is no special keyword 'abstract' or 'interface'. Abstraction is enforced by pure virtual functions.
Fill both blanks to define a derived class that implements the pure virtual function.
class Circle : public Shape { public: void [1]() override { std::cout << "Drawing Circle" << std::endl; } };
The derived class must implement the pure virtual function 'draw' declared in the base class Shape.
Fill all three blanks to create an abstract class and a derived class that implements its pure virtual function.
class [1] { public: virtual void [2]() = 0; }; class [3] : public [1] { public: void [2]() override { std::cout << "Implemented" << std::endl; } };
The abstract class is Shape with a pure virtual function draw. The derived class Circle implements draw.