| 6 | #include <format> |
| 7 | |
| 8 | class Box |
| 9 | { |
| 10 | public: |
| 11 | // Constructors |
| 12 | Box() = default; |
| 13 | Box(double l, double w, double h) : m_length{ l }, m_width{ w }, m_height{ h } {} |
| 14 | |
| 15 | Box& operator++(); // Prefix ++operator |
| 16 | const Box operator++(int); // Postfix operator++ |
| 17 | Box& operator--(); // Prefix --operator |
| 18 | const Box operator--(int); // Postfix operator-- |
| 19 | |
| 20 | double volume() const { return m_length * m_width * m_height; } |
| 21 | |
| 22 | // Accessors |
| 23 | double getLength() const { return m_length; } |
| 24 | double getWidth() const { return m_width; } |
| 25 | double getHeight() const { return m_height; } |
| 26 | |
| 27 | std::partial_ordering operator<=>(const Box& otherBox) const |
| 28 | { |
| 29 | return volume() <=> otherBox.volume(); |
| 30 | } |
| 31 | std::partial_ordering operator<=>(double otherVolume) const |
| 32 | { |
| 33 | return volume() <=> otherVolume; |
| 34 | } |
| 35 | |
| 36 | bool operator==(const Box& otherBox) const = default; |
| 37 | |
| 38 | private: |
| 39 | double m_length{ 1.0 }; |
| 40 | double m_width{ 1.0 }; |
| 41 | double m_height{ 1.0 }; |
| 42 | }; |
| 43 | |
| 44 | inline Box& Box::operator++() // Prefix ++operator |
| 45 | { |
nothing calls this directly
no outgoing calls
no test coverage detected