//array.cpp

template <class T>
Array<T>& Array_Itr<T>::operator=(T val)	{
   array.values[element] = val;
   return array;
}

template <class T>
Array_Itr<T>::operator T()	{
   return array.values[element];
}

template <class T>
Array<T>::Array(int sz, char* n)	: name(n)	{
   values = new T[size=sz];
   if (!values)	{
	size = 0;
	throw ArrayError(name,"Array()",ArrayError::Memory);
   }
}

template <class T>
Array_Itr<T> Array<T>::operator[](int idx)  {
   if ((idx < 0) || (idx >= size))	{
	throw ArrayError(name,"operator[]()",ArrayError::Range,idx);
   }
   return Array_Itr<T>(*this,idx);
}

inline ostream& operator<<(ostream& o, ArrayError &e)	{
   if (e.type == ArrayError::Memory) 		cerr << "Memory Allocation Error:";
   else if (e.type == ArrayError::Range)	cerr << "Range Error:";
   cerr << e.name << "." << e.service;
   if (e.type == ArrayError::Range)			cerr << ", Index=" << e.index;
   return o;
}


