57: template <class T>
58: Array<T>::Array(const Array<T> &rhs)
59: {
60: itsSize = rhs.GetitsSize();
61: pType = new T[itsSize];
62: for (int i = 0; i < itsSize; i++)
63: pType[i] = rhs[i];
64: }
65:
66: template <class T>
67: T& Array<T>::operator[](int offSet)
68: {
69: int size = GetitsSize();
70: if (offSet >= 0 && offSet < GetitsSize())
71: return pType[offSet];
72: throw xBoundary();
73: return pType[0];
74: }
75:
76: template <class T>
77: const T& Array<T>::operator[](int offSet) const
78: {
79: int mysize = GetitsSize();
80: if (offSet >= 0 && offSet < GetitsSize())
81: return pType[offSet];
82: throw xBoundary();
83: }
84:
85: template <class T>
86: ostream& operator<< (ostream& output, const Array<T>& theArray)
87: {
88: for (int i = 0; i < theArray.GetitsSize(); i++)
89: output << “[“ << i << “] “ << theArray[i] << endl;
90: return output;
91: }
92:
93:
94: int main()
95: {
96: try
97: {
98: Array<int> intArray(9);
99: for (int j = 0; j < 100; j++)
100: {
101: intArray[j] = j;
102: cout << “intArray[“ << j << “] okay...” << endl;
103: }
104: }
744 Day 20
LISTING20.9 continued