devxlogo

Placement New Objects Must be Destroyed Explicitly

Placement New Objects Must be Destroyed Explicitly

Objects constructed on a pre-allocated buffer by using placement new must be destroyed explicitly.

 #include #include using namespace std;class C{public:	C() { coutC::~C(); //explicit destructor invocation is required delete [] p;  return 0;}

Without an explicit destructor invocation, the object would never be destroyed, yet the memory on which it was created would be released by the delete[] statement.

devx-admin

Share the Post: