Beispiel #1
0
tvector<itemType>::tvector(const tvector<itemType> & vec)
// postcondition: vector is a copy of vec
    : mySize(vec.size()),
      myCapacity(vec.capacity()),
      myList(new itemType[myCapacity])
{
    int k;
        // copy elements
    for(k = 0; k < mySize; k++){
        myList[k] = vec.myList[k];
    }
}
Beispiel #2
0
const tvector<itemType> &
tvector<itemType>::operator = (const tvector<itemType> & rhs)
// postcondition: normal assignment via copying has been performed;
//                if vector and rhs were different sizes, vector
//                has been resized to  match the size of rhs
{
    if (this != &rhs)                           // don't assign to self!
    {
        delete [] myList;                       // get rid of old storage
        myCapacity = rhs.capacity();
        mySize =     rhs.size();
        myList = new itemType [myCapacity];         // allocate new storage

            // copy rhs
        int k;
        for(k=0; k < mySize; k++)
        {
            myList[k] = rhs.myList[k];
        }
    }
    return *this;                               // permit a = b = c = d
}