Source of MagicBox.cpp


  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: #include "MagicBox.h"

  9: template<class ItemType>
 10: MagicBox<ItemType>::MagicBox()
 11: {
 12:    PlainBox<ItemType>();
 13:    firstItemStored = false; // Box has no magic initially
 14: } // end default constructor

 16: template<class ItemType>
 17: MagicBox<ItemType>::MagicBox(const ItemType& theItem)
 18: {
 19:    firstItemStored = false; // Box has no magic initially
 20:    setItem(theItem);
 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