Practice ยท 1 of 3
Abstract shapes with dispatch
Implement class Shape with a pure virtual double area() const, a pure virtual const char* name() const, and a public virtual destructor (virtual ~Shape() = default;). Implement Square(double side) and Circle(double radius) overriding both. The test stores them in a std::vector<std::unique_ptr<Shape>> and checks dispatch + the vtable-aware destructor path.
Difficulty: intermediate
Press Submit to check your solution.
Back to lesson: Practice: Polymorphism and the virtual destructor rule