 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
//Implementation
of dyn_a1 constructor and destructor
|
|
inline
dyn_a1::dyn_a1(INDEX i) throw(bad_alloc) :
|
|
d1(0) { //set to 0 in case of exception
|
|
a0 = new int[i]; //total # elements for 1D array
|
|
d1 = i; //# of 1D array elements
|
|
}
|
|
inline
dyn_a1::~dyn_a1() throw() {
|
|
delete[] a0; //deallocate all array elements
|
|
}
|
|
|
//Implementation
of subscript operator
|
|
inline
int &dyn_a1::operator[](INDEX i) throw(bad_index) {
|
if (i<0 || i>=d1) { //check if out of bounds
|
|
bad_index e; //create bad_index object
|
|
e.index = i; //save bad index
|
|
throw(e); //throw bad_index exception
|
|
}
|
|
return (a0[i]); //ith element in 1D array
|
|
}
|
|