[ Post New Message | Post Reply to this One | Send Private Email to Steve Heller | Help ]

Reference argument to operator =

from Steve Heller (stheller@koyote.com)
Yes, the copy constructor that we've already written does prevent that particular danger in this case. However, there is another reason that we have to use a reference argument to operator = rather than a value argument: calling the copy constructor to make a copy creates a great deal of additional work to be performed for no reason. As a thought experiment, try to figure out all the function calls that would be executed in the processing of the statement "a = b;" if operator= used a value argument. For extra credit, figure out what would happen if the statement "a=a;" were executed under the same conditions.
(posted 8295 days ago)

[ Previous | Next ]