Jacob Jensen wrote:
Try:
so1 = SomeObject();
Does this not require implementing a copy constructor, because if the
default is not good enough, you might not get all the data
reinitialized. Or have got something wrong here?
The above doesn't use the copy constructor, but the assignment operator.
Often, the default for both copy constructor and assignment operator is
enough. But if it's not for your class, you should implement them
anyway since a class that you are not allowed to copy even though its
interface claims it be copyable is broken. Alternatively, if the class
is not supposed to be copied, the copy constructor and assignment
operator should be declared private and not implemented. In this case,
the above solution will of course not work. Another alternative (that
has its own problems though and is not really a good design, so I
advice against it) is to destroy and reconstruct the object in-place by
doing:
so1.~SomeObject();
new (&so1) SomeObject(); // #include <new>