I have a question about assignment operator when using copy-and-swap method.
String & operator = (String s) // the pass-by-value parameter serves as a temporary
{
s.swap (*this); // Non-throwing swap
return *this;
}// Old resources released when destructor of s is called.
Let's suppose we have a good copy constructor which deep-copy all the pointers and dynamic allocated variables.
Then, what's the difference between above code and below code?
String & operator = (String s) // the pass-by-value parameter serves as a temporary
{
return s;
}
Since, we have a good copy constructor, I think another object, s, is created inside the operator= function. So, what's the point of using non-throwing swap function?