1: // Created by Frank M. Carrano and Timothy M. Henry.
2: // Copyright (c) 2017 Pearson Education, Hoboken, New Jersey.
4: // Section C2.4
6: #include <iostream>
7: #include <string>
8: #include "PlainBox.h"
9: #include "MagicBox.h"
11: void placeInBox(PlainBox<std::string>* theBox, std::string theItem)
12: {
13: theBox->setItem(theItem);
14: } // end placeInBox
16: int main()
17: {
18: std::string specialItem = "Riches beyond compare!";
19: std::string hammerItem = "Hammer";
20:
21: PlainBox<std::string>* myPlainBoxPtr = new PlainBox<std::string>();
22: placeInBox(myPlainBoxPtr, hammerItem); // Stores hammerItem
23: placeInBox(myPlainBoxPtr, specialItem); // Stores specialItem
24: std::cout << myPlainBoxPtr–>getItem() << std::endl; // Displays specialItem
25:
26: MagicBox<std::string>* myMagicBoxPtr = new MagicBox<std::string>();
27: placeInBox(myMagicBoxPtr, hammerItem); // Stores hammerItem
28: placeInBox(myMagicBoxPtr, specialItem); // Ignores specialItem
29: std::cout << myMagicBoxPtr –>getItem() << std::endl; // Displays hammerItem
30:
31: delete myPlainBoxPtr;
32: myPlainBoxPtr = nullptr;
33: delete myMagicBoxPtr;
34: myMagicBoxPtr = nullptr;
35:
36: return 0;
37: } // end main