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

Class Box

Examples/NoModules/Chapter 15/Ex15_07A/Box.h:5–22  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3#include <iostream>
4
5class Box
6{
7public:
8 Box() : Box{ 1.0, 1.0, 1.0 } {}
9 Box(double l, double w, double h) : m_length {l}, m_width {w}, m_height {h} {}
10
11 virtual ~Box() = default;
12
13 // Function to show the volume of an object
14 void showVolume() const
15 { std::cout << "Box usable volume is " << volume() << std::endl; }
16
17 // Function to calculate the volume of a Box object
18 virtual double volume() const { return m_length * m_width * m_height; }
19
20protected: // Should be private in production-quality code (add getters to access)
21 double m_length, m_width, m_height;
22};
23
24#endif

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected