#include<iostream>
using namespace std;
class shape
{
public:
shape()
{
cout << "ctor" ;
}
~shape()
{
cout << "Dtor";
}
};
int main()
{
shape a;//ctor,Dtor。
shape* b = new shape;//ctor,无Dtor,若后面添加一条语句delete b;,则有ctor,Dtor。
//delete b;
return 0;
}
运行结果:
后面添加一条语句delete b;,则有ctor,Dtor: