: Explicit calls of destructors are rarely needed
. One use of such calls is for objects placed at specific
addresses using a placement
new-expression. Such use of explicit placement and destruction of objects can be necessary
to cope with dedicated hardware resources and for writing memory management
facilities
. For example,
void* operator new(std::size_t, void* p) { return p; }
struct X {
X(int);
~X();
};
void f(X* p);
void g() { char* buf = new char[sizeof(X)];
X* p = new(buf) X(222); f(p);
p->X::~X(); }
—
end note