The standard shows this example Β§ 3.8 67 N3690:
struct C {
int i;
void f();
const C& operator=( const C& );
};
const C& C::operator=( const C& other) {
if ( this != &other ) {
this->~C();
new (this) C(other);
f();
}
return *this;
}
C c1;
C c2;
c1 = c2;
c1.f();
Note that this example completes the lifetime of an object before constructing a new object in place (compare with your code that does not call the destructor).
, :
, , , , , , , , , , :
- , - , ( cv-qualifiers)
- const-qualified, , , - , ,
- (1.8) T T (.. ).
"", .
( , ), undefined .
, vtable, , , , vtable , , , sizeof , , .