// File: twodim8.H // // A two-dimensional array of int ADT. // This version IS templated AND has a nested SmartPtr class. // This time A[][] checks for out of bounds // The SmartIntPtr class is only used by TwoDim Array. // It does not allocate memory at all. // This class does not need a copy constructor or // overloaded assignment operator. #ifndef TWODIM_H #define TWODIM_H template class TwoDimArray { public: // Constructors TwoDimArray() ; TwoDimArray(unsigned int r, unsigned int c) ; // Copy Constructor TwoDimArray(const TwoDimArray& A) ; // Destructor ~TwoDimArray() ; TwoDimArray& operator=(const TwoDimArray& rhs) ; void Print() ; T& at(unsigned int r, unsigned int c) ; private: class SmartPtr ; public: SmartPtr operator[] (unsigned int r) ; private: unsigned int rows, cols ; T *M ; } ; template class TwoDimArray::SmartPtr { public: // Constructors SmartPtr() ; SmartPtr(T *ptr, unsigned int size) ; // Overload [] T& operator[] (unsigned int c) ; private: T *p ; int n ; } ; #include "twodim8.cpp" #endif