I came across an example:
#include <iostream>
#include <stdexcept>
using namespace std;
class A{
public:
A():m_n(m_object_id++){}
~A(){cout << m_n;}
private:
const int m_n;
static int m_object_id;
};
int A::m_object_id=0;
int main()
{
A * const p = new A[3];
A * const q = reinterpret_cast<A * const> (new char[3*sizeof(A)]);
new (q) A;
new (q+1)A;
q->~A();
q[1].~A();
delete [] reinterpret_cast<char *>(q); // -> here
delete[] p;
cout << endl;
return 0;
}
the output:
34210
Can someone explain delete [] reinterpret_cast<char *>(q); // -> here
, what it is doing and producing any output?
EDIT
My question is delete [] reinterpret_cast<char *>(q);
not calling ~A(){cout << m_n;}
, like delete[] p;
, why so ?