25: class xBoundary {};
26: class xTooBig {};
27: class xTooSmall{};
28: class xZero {};
29: class xNegative {};
30: private:
31: int *pType;
32: int itsSize;
33: };
34:
35: int& Array::operator[](int offSet)
36: {
37: int size = GetitsSize();
38: if (offSet >= 0 && offSet < GetitsSize())
39: return pType[offSet];
40: throw xBoundary();
41: return pType[0]; // appease MFC
42: }
43:
44:
45: const int& Array::operator[](int offSet) const
46: {
47: int mysize = GetitsSize();
48: if (offSet >= 0 && offSet < GetitsSize())
49: return pType[offSet];
50: throw xBoundary();
51:
52: return pType[0]; // appease MFC
53: }
54:
55:
56: Array::Array(int size):
57: itsSize(size)
58: {
59: if (size == 0)
60: throw xZero();
61: if (size < 10)
62: throw xTooSmall();
63: if (size > 30000)
64: throw xTooBig();
65: if (size < 1)
66: throw xNegative();
67:
68: pType = new int[size];
69: for (int i = 0; i < size; i++)
70: pType[i] = 0;
71: }
72:
730 Day 20
LISTING20.5 continued