| 5 | #include "Carton.h" // For the Carton class |
| 6 | |
| 7 | int main() |
| 8 | { |
| 9 | // Box box{20.0, 30.0, 40.0}; // Uncomment for compiler error |
| 10 | |
| 11 | ToughPack hardcase {20.0, 30.0, 40.0}; // A derived box - same size |
| 12 | Carton carton {20.0, 30.0, 40.0, "plastic"}; // A different derived box |
| 13 | |
| 14 | Box*pBox {&hardcase}; // Base pointer - derived address |
| 15 | std::cout << "hardcase volume is " << pBox->volume() << std::endl; |
| 16 | |
| 17 | pBox = &carton; // New derived address |
| 18 | std::cout << "carton volume is " << pBox->volume() << std::endl; |
| 19 | } |