MCPcopy Create free account
hub / github.com/Apress/beginning-cpp20 / Box

Class Box

Examples/NoModules/Chapter 20/Ex20_16/Box.h:6–35  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4#include <compare> // For std::partial_ordering (see Chapter 4)
5
6class Box
7{
8public:
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
31private:
32 double m_length{ 1.0 };
33 double m_width{ 1.0 };
34 double m_height{ 1.0 };
35};
36
37#endif

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected