MCPcopy Create free account
hub / github.com/Apress/beginning-cpp20 / main

Function main

Examples/Modules/Chapter 15/Ex15_03/Ex15_03.cpp:5–30  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3import boxes;
4
5int 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// Uncomment the following statement for an error
16// std::cout << "\nhardcase volume is " << hardcase.volume() << std::endl;
17
18 // Now using a base pointer...
19 Box* base {&box}; // Points to type Box
20 std::cout << "\nbox volume through base pointer is " << base->volume() << std::endl;
21 base->showVolume();
22
23 base = &hardcase; // Points to type ToughPack
24 std::cout << "hardcase volume through base pointer is " << base->volume() << std::endl;
25 base->showVolume();
26
27 base = &carton; // Points to type Carton
28 std::cout << "carton volume through base pointer is " << base->volume() << std::endl;
29 base->showVolume();
30}

Callers

nothing calls this directly

Calls 2

showVolumeMethod · 0.45
volumeMethod · 0.45

Tested by

no test coverage detected