It seems you have configured the assignment operator correctly:
T& T::operator= (T value) { value. swap(*this); return *this; }
The argument is passed in as a copy to the binding operator, and the compiler really needs to make that copy in your setup. If you went through a temporary copy, you could avoid:
o2 = A();
Thus, the implementation above actually has several interesting properties:
- it uses the functions already written: the copy constructor is either generated or written, but does the right thing, and if you want to have a job, you probably want to have a
swap()
member as well - assignment is a strong exception if the
swap()
operation is not thrown, as it should be. When dispensers enter an image, everything should be done a little differently, although - assignment tries to avoid the actual copy operations, since the copy may be deleted in some cases during the transfer of the argument, i.e. the contents are just
swap()
ed in place
source share