// File: twodim5.h // // A two-dimensional array of int ADT. // This version is NOT templated, but has a nested SmartIntPtr class. // In version 5, we use a class declaration of SmartIntPtr in // TwoDimArray, but defining it separately, outside. // // 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 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() ; int& at(unsigned int r, unsigned int c) ; private: class SmartIntPtr ; // to be defined later public: SmartIntPtr operator[] (unsigned int r) ; private: unsigned int rows, cols ; int *M ; } ; class TwoDimArray::SmartIntPtr { public: // Constructors SmartIntPtr() ; SmartIntPtr(int *ptr, unsigned int size) ; // Overload [] int& operator[] (unsigned int c) ; private: int *p ; int n ; } ; #endif