What does memory reuse mean? For instance, we've created and object.
struct A { };
A *a = new A;
void *p = operator new(sizeof(A),a); //Is it memory reusing?
void *p = realloc(sizeof(A),a); //Is it memory reusing?
I ask that question because the example from the section 3.8/6 confuses me. The example:
#include <cstdlib>
struct B {
virtual void f();
void mutate();
virtual ~B();
};
struct D1 : B { void f(); };
struct D2 : B { void f(); };
void B::mutate() {
new (this) D2; //1, reuses storage — ends the lifetime of *this
f(); // undefined behavior
... = this; // OK, this points to valid memory
}
That is, at //1
we first call placement-new
which reuses memory, and just after this we construct a new object. Right?