在堆中分配空间,需要手动delete才会执行析构函数.

来源:互联网 发布:淘宝店铺怎么铺货 编辑:程序博客网 时间:2024/06/05 13:10
 

#include <iostream>
using namespace std;

class A
{
public:
 A()
 {
  cout<<"The constructor in operation."<<endl;
 }
 ~A()
 {
  cout<<"Destructor function in operation."<<endl;
 }
};

void main()
{
 A *p1=new A;
// delete p1;  此句删除,将不执行析构函数,浪费了内存空间.
}

原创粉丝点击