// File: Array.h // Template array class definition and implementation // Written by Daniel Spiegel #ifndef ARRAY_H #define ARRAY_H #include #include using namespace std; template class Array; // Need this to forward declare the << operator template ostream& operator<<(ostream &,const Array &); // Now, the class template class Array { public: // default constructor Array(int n = 10); // constructor initializes elements to given value Array(int n, const eltType &val); // constructor initializes from a standard array Array(const eltType A[], int n); // copy constructor Array(const Array &A); // destructor ~Array(); // append element to array Array &operator+=(eltType); // inspector for size of the list int size() const { return items; } // assignment operator Array &operator=(const Array &A); // inspector for element of a constant list const eltType& operator[](int i) const; // inspector for element of a nonconstant list eltType& operator[](int i); private: // data members eltType *elements;// pointer to list elements int items; // size of list }; #endif