Loading...
Searching...
No Matches

Abstract base class for all 2D shapes. More...

#include <shapes.hpp>

Inheritance diagram for geometry::Shape:
[legend]

Public Member Functions

virtual ~Shape ()=default
 Virtual destructor for safe polymorphic deletion.
 
virtual double area () const =0
 Compute the area of the shape.
 
std::string describe () const
 Pretty-print shape information.
 
virtual std::string name () const =0
 Return the human-readable name of the shape.
 
virtual double perimeter () const =0
 Compute the perimeter of the shape.
 

Static Public Member Functions

static int instance_count ()
 Get the total count of Shape instances created.
 

Protected Member Functions

 Shape ()
 Increment the instance counter.
 

Detailed Description

Abstract base class for all 2D shapes.

Every shape must provide its area, perimeter, and a human-readable name. The Shape class also tracks the total number of shape instances created (demonstrating static member documentation).

Note
Shapes are non-copyable by design. Use std::unique_ptr<Shape> for polymorphic ownership.
See also
Circle, Rectangle, Triangle, Square

Definition at line 47 of file shapes.hpp.

Constructor & Destructor Documentation

◆ ~Shape()

virtual geometry::Shape::~Shape ( )
virtualdefault

Virtual destructor for safe polymorphic deletion.

◆ Shape()

geometry::Shape::Shape ( )
inlineprotected

Increment the instance counter.

Definition at line 87 of file shapes.hpp.

87{ ++instance_count_; }

Member Function Documentation

◆ area()

virtual double geometry::Shape::area ( ) const
nodiscardpure virtual

Compute the area of the shape.

Returns
The area in square units.

Implemented in geometry::Circle, geometry::Rectangle, and geometry::Triangle.

Referenced by describe().

◆ describe()

std::string geometry::Shape::describe ( ) const
inlinenodiscard

Pretty-print shape information.

Returns
A formatted string: "ShapeName(area=..., perimeter=...)".

Definition at line 74 of file shapes.hpp.

74 {
75 return name() + "(area=" + std::to_string(area())
76 + ", perimeter=" + std::to_string(perimeter()) + ")";
77 }
virtual std::string name() const =0
Return the human-readable name of the shape.
virtual double perimeter() const =0
Compute the perimeter of the shape.
virtual double area() const =0
Compute the area of the shape.

References area(), name(), and perimeter().

◆ instance_count()

static int geometry::Shape::instance_count ( )
inlinestatic

Get the total count of Shape instances created.

Returns
The running total.

Definition at line 83 of file shapes.hpp.

83{ return instance_count_; }

◆ name()

virtual std::string geometry::Shape::name ( ) const
nodiscardpure virtual

Return the human-readable name of the shape.

Returns
A string like "Circle", "Rectangle", etc.

Implemented in geometry::Circle, geometry::Rectangle, geometry::Square, and geometry::Triangle.

Referenced by describe().

◆ perimeter()

virtual double geometry::Shape::perimeter ( ) const
nodiscardpure virtual

Compute the perimeter of the shape.

Returns
The perimeter in linear units.

Implemented in geometry::Circle, geometry::Rectangle, and geometry::Triangle.

Referenced by describe().


The documentation for this class was generated from the following file: