I am trying to understand placement new-expressions in C++.
This Stack Overflow answer states that T* p = new T(arg);
is equivalent to
void* place = operator new(sizeof(T)); // storage allocation
T* p = new(place) T(arg); // object construction
and that delete p;
is equivalent to
p->~T(); // object destruction
operator delete(p); // storage deallocation
Why do we need the placement new-expression in T* p = new(place) T(arg);
for object construction, isn’t the following equivalent?
T* p = (T*) place;
*p = T(arg);