1: // Created by Frank M. Carrano and Tim Henry. 2: // Copyright (c) 2013 __Pearson Education__. All rights reserved. 4: // Section C2.2 6: #include <iostream> 7: #include <string> 8: #include "PlainBox.h" 9: #include "MagicBox.h" 11: using namespace std; 13: void placeInBox(PlainBox<string>& theBox, string theItem) 14: { 15: theBox.setItem(theItem); 16: } // end placeInBox 18: int main() 19: { 20: string specialItem = "Riches beyond compare!"; 21: string otherItem = "Hammer"; 22: 23: PlainBox<string> myPlainBox; 24: placeInBox(myPlainBox, specialItem); 25: 26: MagicBox<string> myMagicBox; 27: placeInBox(myMagicBox, otherItem); 28: placeInBox(myMagicBox, specialItem); // specialItem is stored! 29: 30: cout << myMagicBox.getItem() << endl; // "Riches beyond compare!" 31: 32: PlainBox<string> mySpecialBox = MagicBox<string>(); 33: mySpecialBox.setItem(otherItem); 34: mySpecialBox.setItem(specialItem); // specialItem is stored! 35: cout << mySpecialBox.getItem() << endl; // "Riches beyond compare!" 36: 37: return 0; 38: } // end main 40: /* 41: Riches beyond compare! 42: Riches beyond compare! 44: */