Listing C2-1 (In PowerPoint Slides)
Listing C2-3
Listing C2-3
Listing
C2-4
Listing C2-2 Header file for the class GoodMemory |
/** @file GoodMemory.h */
#include
#include "ToyBox.h"
using namespace std;
class GoodMemory
{
private:ToyBox < string > *someBoxPtr;
public:GoodMemory (); // Default constructor
~GoodMemory (); // Destructor
void fi xedLeak (const double &someItem);
}; // end GoodMemory
|
/** @file GoodMemory.cpp */
#include "GoodMemory.h"
GoodMemory::GoodMemory ():someBoxPtr (nullptr)
{
} // end default constructor
GoodMemory::~GoodMemory ()
{
delete someBoxPtr;
} // end destructor
void
GoodMemory::fixedLeak (const double &someItem)
{
someBoxPtr = new ToyBox < double >();
someBoxPtr->setItem (someItem);
} // end fixedLeak
|
/** @file PlainBox.h */
#ifndef _PLAIN_BOX
#define _PLAIN_BOX
template < class ItemType >; // Indicates this is a template
// Declaration for the class PlainBox
class PlainBox
{
private:
// Data field
ItemType item;
public:
// Default constructor
PlainBox ();
// Parameterized constructor
PlainBox (const ItemType & theItem);
// Mutator method that can change the value of the data fi eld
virtual void setItem (const ItemType & theItem);
// Accessor method to get the value of the data fi eld
virtual ItemType getItem () const;
}; // end PlainBox
#include "PlainBox.cpp" // Include the implementation fi le
#endif
|