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