#include<iostream>#include<cstdlib>usingnamespacestd;classA{public:A(void){cout<<"A::A()"<<endl;}~A(void){cout<<"A::~A()"<<endl;}staticvoid*operatornew(size_tsize){cout<<"A::new"<<endl;void*pv=malloc(size);returnpv;}staticvoidoperatordelete(void*pv){cout<<"A::delete"<<endl;free(pv);}};intmain(void){A*pa=newA;deletepa;return0;}

结果为:

A::new

A::A()

A::~A()

A::delete

由此我们可以知道,new 对象时,先new在调用其构造,

delete对象的时,先调用其析构,再delete