Image

Imagecgs3408h4x wrote in Imagecpp getting work done

Listens: George Strait- You'll Be There

Question About Assignment Operator

This may be a rather simple, but when doing and operator overload of the assignment operator, is it standard procedure to check for self assignment, or do you only need to check for self assignment when you're working with dynamic data that you delete the old data?

For example, are you required to write this everytime?
template <typename K, typename V, class H, class C>
CHashTableIterator <K,V,H,C> & CHashTableIterator <K,V,H,C>::
operator = (const CHashTableIterator <K,V,H,C> & I) { if (&I != this) { bucketNum = I.bucketNum; tablePtr = I.tablePtr; bucketItr = I.bucketItr; } return *this; }

Or can you do this:

template <typename K, typename V, class H, class C>
CHashTableIterator <K,V,H,C> & CHashTableIterator <K,V,H,C>::
operator = (const CHashTableIterator <K,V,H,C> & I) { bucketNum = I.bucketNum; tablePtr = I.tablePtr; bucketItr = I.bucketItr; return *this; }


Thanks for the help all!