1: // Created by Frank M. Carrano and Tim Henry. 2: // Copyright (c) 2013 __Pearson Education__. All rights reserved. 4: /** Listing C1-7. 5: @file MagicBox.cpp */ 7: template<class ItemType> 8: MagicBox<ItemType>::MagicBox() 9: { 10: PlainBox<ItemType>(); 11: firstItemStored = false; // Box has no magic initially 12: } // end default constructor 14: template<class ItemType> 15: MagicBox<ItemType>::MagicBox(const ItemType& theItem) 16: { 17: firstItemStored = false; // Box has no magic initially 18: setItem(theItem); 19: // Box has magic now 20: } // end constructor 22: template<class ItemType> 23: void MagicBox<ItemType>::setItem(const ItemType& theItem) 24: { 25: if (!firstItemStored) 26: { 27: PlainBox<ItemType>::setItem(theItem); 28: firstItemStored = true; // Box now has magic 29: } // end if 30: } // end setItem