Skip to main content

Practice · 1 of 3

Abstract shapes with dispatch

CHALLENGE
Difficulty: intermediate+25 XP

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.

Back to lesson: Practice: Polymorphism and the virtual destructor rule