Handling Errors and Exceptions 725
20
18: // accessors
19: int GetitsSize() const { return itsSize; }
20:
21: // friend function
22: friend ostream& operator<< (ostream&, const Array&);
23:
24: class xBoundary {}; // define the exception class
25:
26: private:
27: int *pType;
28: int itsSize;
29: };
30:
31: Array::Array(int size):
32: itsSize(size)
33: {
34: pType = new int[size];
35: for (int i = 0; i < size; i++)
36: pType[i] = 0;
37: }
38:
39: Array& Array::operator=(const Array &rhs)
40: {
41: if (this == &rhs)
42: return *this;
43: delete [] pType;
44: itsSize = rhs.GetitsSize();
45: pType = new int[itsSize];
46: for (int i = 0; i < itsSize; i++)
47: {
48: pType[i] = rhs[i];
49: }
50: return *this;
51: }
52:
53: Array::Array(const Array &rhs)
54: {
55: itsSize = rhs.GetitsSize();
56: pType = new int[itsSize];
57: for (int i = 0; i < itsSize; i++)
58: {
59: pType[i] = rhs[i];
60: }
61: }
62:
63: int& Array::operator[](int offSet)
64: {
65: int size = GetitsSize();
LISTING20.4 continued