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

Class Box

Examples/NoModules/Chapter 13/Ex13_04/Box.h:8–37  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6#include <format>
7
8class Box
9{
10public:
11 // Constructors
12 Box() = default;
13 Box(double l, double w, double h) : m_length{ l }, m_width{ w }, m_height{ h } {}
14
15 double volume() const { return m_length * m_width * m_height; }
16
17 // Accessors
18 double getLength() const { return m_length; }
19 double getWidth() const { return m_width; }
20 double getHeight() const { return m_height; }
21
22 std::partial_ordering operator<=>(const Box& otherBox) const
23 {
24 return volume() <=> otherBox.volume();
25 }
26 std::partial_ordering operator<=>(double otherVolume) const
27 {
28 return volume() <=> otherVolume;
29 }
30
31 bool operator==(const Box& otherBox) const = default;
32
33private:
34 double m_length{ 1.0 };
35 double m_width{ 1.0 };
36 double m_height{ 1.0 };
37};
38
39inline std::ostream& operator<<(std::ostream& stream, const Box& box)
40{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected