n//Implementation of
dyn_a1 constructor and destructor
ninline
dyn_a1::dyn_a1(INDEX i) throw(bad_alloc) :
n d1(0) { //set to 0 in case of
exception
n a0 = new int[i]; //total # elements for 1D array
n d1 = i; //# of 1D array
elements
n}
ninline
dyn_a1::~dyn_a1() throw() {
n delete[] a0; //deallocate all array
elements
n}
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 bad_index e; //create bad_index object
n e.index = i; //save bad index
n throw(e); //throw bad_index
exception
n }
n return (a0[i]); //ith element in 1D array
n}
n