23: };
24:
25: // extraction operator for printing animals
26: ostream& operator<<
27: (ostream& theStream, const Animal& theAnimal)
28: {
29: theStream << theAnimal.GetWeight();
30: return theStream;
31: }
32:
33: Animal::Animal(int weight):
34: itsWeight(weight)
35: {
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: Array(int itsSize = ::DefaultSize);
55: Array(const Array &rhs);
56: ~Array() { delete [] pType; }
57:
58: // operators
59: Array& operator=(const Array&);
60: T& operator[](int offSet) { return pType[offSet]; }
61: const T& operator[](int offSet) const
62: { return pType[offSet]; }
63:
64: // accessors
65: int GetSize() const { return itsSize; }
66: // friend function
67: // template <class T>
68: friend ostream& operator<< (ostream&, const Array<T>&);
69:
70: private:
71: T *pType;
684 Day 19
LISTING19.6 continued