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

Class Box

Examples/NoModules/Chapter 13/Ex13_06/Box.h:7–36  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5#include <ostream> // For std::ostream
6
7class Box
8{
9public:
10 Box() = default; // Default constructor
11 Box(double length, double width, double height)
12 : m_length{ std::max(length,width) }
13 , m_width { std::min(length,width) }
14 , m_height{ height }
15 {}
16
17 double volume() const; // Function to calculate the volume
18
19 // Accessors
20 double getLength() const { return m_length; }
21 double getWidth() const { return m_width; }
22 double getHeight() const { return m_height; }
23
24 // Functions that add full support for comparison operators
25 std::partial_ordering operator<=>(const Box& aBox) const;
26 std::partial_ordering operator<=>(double value) const;
27 bool operator==(const Box& aBox) const = default;
28
29 Box& operator+=(const Box& aBox); // Function to add a Box objects
30 Box operator+(const Box& aBox) const; // Function to add two Box objects
31
32private:
33 double m_length {1.0};
34 double m_width {1.0};
35 double m_height {1.0};
36};
37
38std::ostream& operator<<(std::ostream& stream, const Box& box);
39

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected