When writing a custom assignment operator, is there a caveat to first copying the whole object with a memcpy rather than tediously field by field, and then fixing the pointers and such? This is what I mean:
MyObject& MyObject::operator=(const MyObject &o)
{
memcpy(this, &o, sizeof(MyObject)); // Copy everything in one go.
// Do other things like fix pointers.
return *this;
}
MyObject& MyObject::operator=(const MyObject &o)
{
memcpy(this, &o, sizeof(MyObject)); // Copy everything in one go.
// Do other things like fix pointers.
return *this;
}
To copy to clipboard, switch view to plain text mode
Bookmarks