n//Implementation of dyn_a1 constructor and
destructor
ninline
dyn_a1::dyn_a1(INDEX i) throw() :
n d1(i), //# of 1D array
elements
n dummy(0) {
n a0 = new(nothrow) int[i]; //total # elements
for 1D array
n if (a0 == 0) { //check if new failed
n cerr <<"new failed in class
dyn_a1" <<endl;
n d1 = 0; //set # elements to zero
n }
n}
ninline
dyn_a1::~dyn_a1() throw() {
n delete[] a0; //deallocate all array
elements
n}
n//Implementation of
subscript operator
ninline int
&dyn_a1::operator[](INDEX i) throw() {
n if (i<0 || i>=d1) { //check if out of bounds
n cerr <<"out of bounds at index
" <<i <<endl;
n return (dummy); //reference to dummy element
n }
n return (a0[i]); //ith element in 1D array
n}
n
n
n