52: {
53: for (int i = 0; i < theArray.itsSize; i++)
54: output << “[“ << i << “] “ << theArray[i] << endl;
55: return output;
56: }
57:
58: // implementations follow...
59:
60: // implement the Constructor
61: template <class T>
62: Array<T>::Array(int size):
63: itsSize(size)
64: {
65: pType = new T[size];
66: for (int i = 0; i < size; i++)
67: pType[i] = 0;
68: }
69:
70: // copy constructor
71: template <class T>
72: Array<T>::Array(const Array &rhs)
73: {
74: itsSize = rhs.GetSize();
75: pType = new T[itsSize];
76: for (int i = 0; i < itsSize; i++)
77: pType[i] = rhs[i];
78: }
79:
80: // operator=
81: template <class T>
82: Array<T>& Array<T>::operator=(const Array &rhs)
83: {
84: if (this == &rhs)
85: return *this;
86: delete [] pType;
87: itsSize = rhs.GetSize();
88: pType = new T[itsSize];
89: for (int i = 0; i < itsSize; i++)
90: pType[i] = rhs[i];
91: return *this;
92: }
93:
94: int main()
95: {
96: bool Stop = false; // flag for looping
97: int offset, value;
98: Array<int> theArray;
99:
100: while (Stop == false)
676 Day 19
LISTING19.4 continued