Source of MagicBox.cpp


  1: //  Created by Frank M. Carrano and Tim Henry.
  2: //  Copyright (c) 2013 __Pearson Education__. All rights reserved.

  4: /** @file MagicBox.cpp */

  6: #include "MagicBox.h"

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

 15: template<class ItemType>
 16: MagicBox<ItemType>::MagicBox(const ItemType& theItem)
 17: {
 18:    firstItemStored = false; // Box has no magic initially
 19:    setItem(theItem);
 20:    // Box has magic now
 21: } // end constructor

 23: template<class ItemType>
 24: void MagicBox<ItemType>::setItem(const ItemType& theItem)
 25: {
 26:    if (!firstItemStored)
 27:    {
 28:       PlainBox<ItemType>::item = theItem; // item has protected access
 29:       firstItemStored = true;             // Box now has magic
 30:    } // end if
 31: } // end setItem