36: //cout << “animal(int) “;
37: }
38:
39: Animal::Animal():
40: itsWeight(0)
41: {
42: //cout << “animal() “;
43: }
44:
45: Animal::~Animal()
46: {
47: //cout << “Destroyed an animal...”;
48: }
49:
50: template <class T> // declare the template and the parameter
51: class Array // the class being parameterized
52: {
53: public:
54: // constructors
55: Array(int itsSize = DefaultSize);
56: Array(const Array &rhs);
57: ~Array() { delete [] pType; itsNumberArrays--; }
58:
59: // operators
60: Array& operator=(const Array&);
61: T& operator[](int offSet) { return pType[offSet]; }
62: const T& operator[](int offSet) const
63: { return pType[offSet]; }
64: // accessors
65: int GetSize() const { return itsSize; }
66: static int GetNumberArrays() { return itsNumberArrays; }
67:
68: // friend function
69: friend ostream& operator<< (ostream&, const Array<T>&);
70:
71: private:
72: T *pType;
73: int itsSize;
74: static int itsNumberArrays;
75: };
76:
77: template <class T>
78: int Array<T>::itsNumberArrays = 0;
79:
80: template <class T>
81: Array<T>::Array(int size = DefaultSize):
82: itsSize(size)
83: {
690 Day 19
LISTING19.7 continued