| 4 | #include <compare> // For std::partial_ordering (see Chapter 4) |
| 5 | |
| 6 | class Box |
| 7 | { |
| 8 | public: |
| 9 | // Constructors |
| 10 | Box() = default; |
| 11 | Box(double l, double w, double h) : m_length{ l }, m_width{ w }, m_height{ h } {} |
| 12 | |
| 13 | double volume() const { return m_length * m_width * m_height; } |
| 14 | |
| 15 | // Accessors |
| 16 | double getLength() const { return m_length; } |
| 17 | double getWidth() const { return m_width; } |
| 18 | double getHeight() const { return m_height; } |
| 19 | |
| 20 | std::partial_ordering operator<=>(const Box& otherBox) const |
| 21 | { |
| 22 | return volume() <=> otherBox.volume(); |
| 23 | } |
| 24 | std::partial_ordering operator<=>(double otherVolume) const |
| 25 | { |
| 26 | return volume() <=> otherVolume; |
| 27 | } |
| 28 | |
| 29 | bool operator==(const Box& otherBox) const = default; |
| 30 | |
| 31 | private: |
| 32 | double m_length{ 1.0 }; |
| 33 | double m_width{ 1.0 }; |
| 34 | double m_height{ 1.0 }; |
| 35 | }; |
| 36 | |
| 37 | #endif |
nothing calls this directly
no outgoing calls
no test coverage detected