The Vec::operator=(const Vec& original) method should:
- Check to see if original and I are different.
(Hint: compare this and the address of original.)
If they are different:
-
Check to see if mySize is different from the size of original.
If so (we need to make them the same size):
- Check to see if mySize is positive.
If so (we need to deallocate our dynamic array):
-
Deallocate the dynamic array whose address is in myArray.
-
Set myArray to nullptr.
-
Check to see if the size of original is positive.
If so (we need to allocate an array the same size):
- allocate a new array that is the same size as that of original,
and store its address in myArray.
- Set mySize to the size of original.
- Set the value of each itemi in myArray to
the value of each itemi from original's array.
- Return myself (using *this).