Would anyone mind explaining this? I get overloading the extraction, insertion, and binary operaotrs. Logically, one would think that after deleting list you wouldn't be able to copy values into another list. I'm just a little confused...are we working with three lists in the function? My book sucks at explaining this.
Right, classes have a built in assignment operator, they keep emphasizing avoiding self assignment. Does the built in assignment avoid this as well? Okay, so the old list is destroyed, and otherList has the base address of the list, but if list is destroyed before it is copied into otherList, how does otherList know what values need to be stored into it? This is just supposed to make a member wise copy of the original list list, correct? And the return value returns the base address of list as well? Thank you for your help Disch.
Oh!!...I think I see what's going on....otherList IS list..right?
And yours would work too, without the need for self-assignment checking,
I don't think it would, because the first thing it does is delete the buffer. So if you self assign, you lose all the data immediately and then explode.
yoked88 wrote:
Okay, so the old list is destroyed, and otherList has the base address of the list, but if list is destroyed before it is copied into otherList, how does otherList know what values need to be stored into it?
There are 2 'list's here.
One belongs to 'this' and is being replaced.
The other belongs to 'otherList'
You are copying otherList's list to this's list.
You are not changing otherList's list, you are only reading it to know what to copy to your new list.
So you delete this's list, then recreate it to match the size of otherList's list. Then you copy the contents of otherLists's list over to this's list.