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

Class Box

Examples/NoModules/Chapter 13/Ex13_09/Box.h:8–42  ·  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 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
38private:
39 double m_length{ 1.0 };
40 double m_width{ 1.0 };
41 double m_height{ 1.0 };
42};
43
44inline Box& Box::operator++() // Prefix ++operator
45{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected