Template Example
//operator=
template <class T>
Array<T>& Array<T>::operator =(const Array &rhs)
{
if (this== &rhs)
//this is a pointer that points to the current object
return *this;
delete [] pType; //When you use[] you are saying to
//delete the whole array, not just one location
itsSize=rhs.GetSize();
pType=new T[itsSize];
for (int i=0; i<itsSize; i++)
pType[i]=rhs[i];
return *this;
Previous slide
Next slide
Back to first slide
View graphic version