// File: twodim9.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 #include using namespace std ; // Forward templated class declaration template class TwoDimArray ; // Forward templated function declaration template ostream& operator << (ostream& out, TwoDimArray& A) ; template class TwoDimArray { friend ostream& operator << (ostream& out, TwoDimArray& A) ; 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 ; unsigned int n ; } ; #include "twodim9.cpp" #endif