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

Class Box

Examples/NoModules/Chapter 14/Ex14_04C/Box.h:8–31  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6#include <format> // For string formatting
7
8class Box
9{
10public:
11 // Constructors
12 Box(double l, double w, double h) : m_length{l}, m_width{w}, m_height{h}
13 { std::cout << "Box(double, double, double) called.\n"; }
14
15 explicit Box(double side) : Box{side, side, side}
16 { std::cout << "Box(double) called.\n"; }
17
18 double volume() const { return m_length * m_width * m_height; }
19
20 // Accessors
21 double getLength() const { return m_length; }
22 double getWidth() const { return m_width; }
23 double getHeight() const { return m_height; }
24
25private:
26 Box() { std::cout << "Box() called.\n"; } // Default constructor (made private)
27
28 double m_length {1.0};
29 double m_width {1.0};
30 double m_height {1.0};
31};
32
33// Stream output for Box objects
34inline std::ostream& operator<<(std::ostream& stream, const Box& box)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected