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

Class Box

Examples/NoModules/Chapter 14/Ex14_04A/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// Box() { std::cout << "Box() called.\n"; } // Default constructor removed!
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
27protected: // Protected to facilitate further examples
28 double m_length {1.0}; // later this chapter (should normally be private)
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