| 3 | #include <iostream> |
| 4 | |
| 5 | int main() |
| 6 | { |
| 7 | // v-- this const was added... |
| 8 | const Box myBox {3.0, 4.0, 5.0}; |
| 9 | std::cout << "myBox dimensions are " << myBox.getLength() |
| 10 | << " by " << myBox.getWidth() |
| 11 | << " by " << myBox.getHeight() << std::endl; |
| 12 | |
| 13 | // Invoking mutators / setters is not possible on a const object: |
| 14 | //myBox.setLength(-20.0); // ignored! |
| 15 | //myBox.setWidth(40.0); |
| 16 | //myBox.setHeight(10.0); |
| 17 | //std::cout << "myBox dimensions are now " << myBox.getLength() // 3 (unchanged) |
| 18 | // << " by " << myBox.getWidth() // by 40 |
| 19 | // << " by " << myBox.getHeight() << std::endl; // by 10 |
| 20 | |
| 21 | std::cout << "myBox's volume is " << myBox.volume() << std::endl; |
| 22 | } |