The only difference I see is that if the Record constructor throws an exception, the first pattern can leave the Record variable equal to the old remote value, while in the second it will be set to NULL .
EDIT:
Indeed, the first sample, if repeated later, will lead to double deletion.
delete record; record = new Record; // Throwing exception // record points to old object // ... later ... delete record; // Double deletion - sky falls down etc.
Safe form:
delete record; record = 0; record = new Record; // Can throw an exception if it likes
Or use std::auto_ptr instead of a raw pointer.
source share