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