1: // Created by Frank M. Carrano and Timothy M. Henry. 2: // Copyright (c) 2017 Pearson Education, Hoboken, New Jersey. 4: /** Listing C1-7. 5: @file MagicBox.cpp */ 7: #include "MagicBox.h" 9: template<class ItemType> 10: MagicBox<ItemType>::MagicBox() : firstItemStored(false) 11: { 12: // PlainBox constructor is called implicitly 13: // Box has no magic initially 14: } // end default constructor 16: template<class ItemType> 17: MagicBox<ItemType>::MagicBox(const ItemType& theItem) : firstItemStore(false) 18: { 19: // Box has no magic initially 20: setItem(theItem); // Calls MagicBox version of setItem 21: // Box has magic now 22: } // end constructor 24: template<class ItemType> 25: void MagicBox<ItemType>::setItem(const ItemType& theItem) 26: { 27: if (!firstItemStored) 28: { 29: PlainBox<ItemType>::setItem(theItem); 30: firstItemStored = true; // Box now has magic 31: } // end if 32: } // end setItem