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

Class Box

Examples/NoModules/Chapter 13/Ex13_02/Box.h:4–29  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2#define BOX_H
3
4class Box
5{
6public:
7 // Constructors
8 Box() = default;
9 Box(double l, double w, double h) : m_length{ l }, m_width{ w }, m_height{ h } {}
10
11 double volume() const { return m_length * m_width * m_height; }
12
13 // Accessors
14 double getLength() const { return m_length; }
15 double getWidth() const { return m_width; }
16 double getHeight() const { return m_height; }
17
18 bool operator<(const Box& aBox) const // Less-than operator
19 {
20 return volume() < aBox.volume();
21 }
22
23 bool operator<(double value) const; // Compare Box volume < double value
24
25private:
26 double m_length{ 1.0 };
27 double m_width{ 1.0 };
28 double m_height{ 1.0 };
29};
30
31// Compare the volume of a Box object with a constant
32inline bool Box::operator<(double value) const

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected