| 5 | #include "Carton.h" // For the Carton class |
| 6 | |
| 7 | int main() |
| 8 | { |
| 9 | Box box {20.0, 30.0, 40.0}; |
| 10 | ToughPack hardcase {20.0, 30.0, 40.0}; // A derived box - same size |
| 11 | Carton carton {20.0, 30.0, 40.0, "Plastic"}; // A different derived box |
| 12 | |
| 13 | box.showVolume(); // Volume of Box |
| 14 | hardcase.showVolume(); // Volume of ToughPack |
| 15 | carton.showVolume(); // Volume of Carton |
| 16 | |
| 17 | // Uncomment the following statement for an error |
| 18 | // std::cout << "\nhardcase volume is " << hardcase.volume() << std::endl; |
| 19 | |
| 20 | // Now using a base pointer... |
| 21 | Box* base {&box}; // Points to type Box |
| 22 | std::cout << "\nbox volume through base pointer is " << base->volume() << std::endl; |
| 23 | base->showVolume(); |
| 24 | |
| 25 | base = &hardcase; // Points to type ToughPack |
| 26 | std::cout << "hardcase volume through base pointer is " << base->volume() << std::endl; |
| 27 | base->showVolume(); |
| 28 | |
| 29 | base = &carton; // Points to type Carton |
| 30 | std::cout << "carton volume through base pointer is " << base->volume() << std::endl; |
| 31 | base->showVolume(); |
| 32 | } |
nothing calls this directly
no test coverage detected