Hey everyone.
Here, in the second answer:
c++ - Why must the copy assignment operator return a reference/const reference? - Stack Overflow
'Alex Collins' gives this example:
Code:
A operator=(const A& rhs) { /* ... */ };
a = b = c; // calls assignment operator twice, calls copy constructor twice, calls destructor type to delete the temporary values! Very wasteful and nothing gained!
To demonstrate why it's not efficient to return by value instead of by reference.
But, in the comment he writes something I didn't expect to:
"calls copy constructor twice"
But I thought so far that if the argument receives the value by reference as in the example above, the copy constructor is not called at all.
That's why we actually strive to send args by reference, not to call the copy constructor, not to create another copy.
So, how is it correct that in his example, the copy constructor is called at all?
Thanks in advance.