Im not one for wrting questions on these things much but this one is bugging me.
// listing 19.3 - Non-Template Friend Classes and Functions
I keep getting the error messageCode:#include <iostream.h> const int DefaultSize = 10; // declare a simple Amimal class so that we can // create an array of animals class Animal { public: Animal(int); Animal(); ~Animal() {} int GetWeight() const { return itsWeight; } void Display() const { cout << itsWeight; } private: int itsWeight; }; Animal::Animal(int weight): itsWeight(weight) {} Animal::Animal(): itsWeight(0) {} template <class T> // declare the template and the parameter class Array // the class being parameterized { public: // Constructors Array(int itsSize = DefaultSize); Array(const Array &rhs); ~Array() { delete [] pType; } // operators Array& operator=(const Array&); T& operator[](int offSet) { return pType[offSet]; } const T& operator[](int offset) const { return pType[offset]; } // accessors int GetSize() const { return itsSize; } // Freind Function friend ostream& operator<< (ostream&,Array<T>&); private: T *pType; int itsSize; }; // friend function. not a template can only be used // with int arrays! Intrudes into private data template <class T> ostream& operator<< (ostream& Output,Array<T>& theArray) { for (int i = 0; i<theArray.GetSize(); i++) Output << "[" << i << "] " << *theArray[i] << endl; return Output; } // implementation follow... // implement the Constructor template <class T> Array<T>::Array(int size): itsSize(size) { pType = new T[size]; for (int i = 0; i < size; i++) pType[i] = 0; } // copy constructor template <class T> Array<T>::Array(const Array &rhs) { itsSize = rhs.GetSize(); pType = new T[itsSize]; for (int i = 0; i < itsSize; i++) pType[i] = rhs[i]; } // operator = template <class T> Array<T>& Array<T>::operator=(const Array &rhs) { if (this == &rhs) return *this; delete [] pType; itsSize = rhs.GetSize(); pType = new T[itsSize]; for (int i = 0; i < itsSize; i++) pType[i] = rhs[i]; return *this; } // driver program int main() { bool Stop = false; // flag for looping int offset, value; Array<int> theArray; while (!Stop) { cout << "Enter an offset (0-9) "; cout << "and a value. (-1 to stop): "; cin >> offset >> value; if (offset < 0) break; if (offset > 9) { cout << "***Please use values between 0 and 9.***\n"; continue; } theArray[offset] = value; } cout << "\nHere's the entire array:\n"; cout << theArray << endl; return 0; }
C:\WINDOWS\TEMP\ccfmpbgb.o(.text+0x1cb):listin~3.c pp: undefined reference to `operator<<(ostream &, Array<int> &)'
can someone please help me
CODE TAGS added by Hammer