| 3 | #include <iostream> |
| 4 | |
| 5 | class Box |
| 6 | { |
| 7 | public: |
| 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 | // Uncomment virtual to ensure destructors of derived classes are called correctly |
| 12 | /*virtual*/ ~Box() { std::cout << "Box destructor called" << std::endl; } |
| 13 | |
| 14 | // More typical declaration of the destructor of a base class |
| 15 | // virtual ~Box() = default; |
| 16 | |
| 17 | // Function to show the volume of an object |
| 18 | void showVolume() const |
| 19 | { std::cout << "Box usable volume is " << volume() << std::endl; } |
| 20 | |
| 21 | // Function to calculate the volume of a Box object |
| 22 | virtual double volume() const { return m_length * m_width * m_height; } |
| 23 | |
| 24 | protected: // Should be private in production-quality code (add getters to access) |
| 25 | double m_length, m_width, m_height; |
| 26 | }; |
| 27 | |
| 28 | #endif |
nothing calls this directly
no outgoing calls
no test coverage detected