Code Fragment: Housekeeping



Vect::Vect(const Vect &a) {		    // copy constructor from a
  vectSize = a.vectSize;		    // copy sizes
  theVect = new int[vectSize];		    // allocate new array
  for (int i = 0; i < vectSize; i++) {	    // copy the vector contents
    theVect[i] = a.theVect[i];
  }
}

Vect& Vect::operator=(const Vect &a) {	    // assignment operator from a
  if (this != &a) {			    // avoid self-assignment
    delete [] theVect;			    // delete old array
    vectSize = a.vectSize;		    // set new size
    theVect = new int[vectSize];	    // allocate new array
    for (int i=0; i < vectSize; i++) {	    // copy the vector contents
      theVect[i] = a.theVect[i];
    }
  }
  return *this;
}