// H. Schellman 4-11-99 
// Improved GeneralArray Class
// This one has copy constructor and assignment

// note use of asserts to trap errors

#ifndef GENERALArray_H
#define GENERALArray_H

#include <iostream.h>
#include <assert.h>

template<class T> 

class GeneralArray{
public:

	// constructors
	GeneralArray();
	GeneralArray(const int size); // make an GeneralArray of size size
	GeneralArray(const int size, const  T  value); // fill the GeneralArray with value

	// The 3 amigos - gotta have these if you use pointers to the heap as data members

	~GeneralArray(){
	delete [] _pointer;
}
	// destructor
	GeneralArray(const  GeneralArray&);  // copy constructor 

    GeneralArray<T>& operator = (const GeneralArray& rhs);  // assignment

	// accessors
	 T  operator [](const int i)const{
		assert (i >= 0 && i < _size);
		return _pointer[i];
}	 // [] for getting values - returns the value

	 T & operator[] (const int i){
		assert (i >= 0 && i < _size);
		return _pointer[i];
	}// [] for setting values - returns reference to the location so you can mess with it

	int size()const;

	// resize the GeneralArray, handy when you've called the default constructor
	void resize(const int newsize);

	// output
	friend ostream& operator << (ostream& o, GeneralArray<T>& a);

protected:
	 T  *_pointer;
	int _size;
};
#endif