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

Function main

Examples/NoModules/Chapter 15/Ex15_04/Ex15_04.cpp:7–31  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5#include "Carton.h" // For the Carton class
6
7int 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 std::cout << "\nhardcase volume is " << hardcase.volume() << std::endl;
18
19 // Now using a base pointer...
20 Box* base{ &box }; // Points to type Box
21 std::cout << "\nbox volume through base pointer is " << base->volume() << std::endl;
22 base->showVolume();
23
24 base = &hardcase; // Points to type ToughPack
25 std::cout << "hardcase volume through base pointer is " << base->volume() << std::endl;
26 base->showVolume();
27
28 base = &carton; // Points to type Carton
29 std::cout << "carton volume through base pointer is " << base->volume() << std::endl;
30 base->showVolume();
31}

Callers

nothing calls this directly

Calls 2

showVolumeMethod · 0.45
volumeMethod · 0.45

Tested by

no test coverage detected