| 6 | #include <format> // For string formatting |
| 7 | |
| 8 | class Box |
| 9 | { |
| 10 | public: |
| 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 | |
| 27 | protected: // 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 |
| 34 | inline std::ostream& operator<<(std::ostream& stream, const Box& box) |
nothing calls this directly
no outgoing calls
no test coverage detected