C++析构函数的调用
2014-04-07 21:23
375 查看
使用new构建的对象,只有当使用delete销毁对象时,才调用析构函数(因为new构造的对象位于堆内存,堆内存要手动释放)
example1
example2
example1
#include <iostream> using namespace std; class A { public: A(); ~A(); private: int a; float b; }; A::A(void) { cout<<"The constructor of the class A"<<endl; } A::~A(void) { cout<<"The deconstructor of the class A"<<endl; } int main(void) { { A a; } system("pause"); return 0; }
example2
#include <iostream> using namespace std; class A { public: A(); ~A(); private: int a; float b; }; A::A(void) { cout<<"The constructor of the class A"<<endl; } A::~A(void) { cout<<"The deconstructor of the class A"<<endl; } int main(void) { { A *a=new A(); } system("pause"); return 0; }
相关文章推荐
- C++ cin cout
- C++11 自动类型推断和类型获取
- OpenCV学习C++接口:图像锐化
- C/C++混合编程--extern “C” 使用方法详解
- Pat(Advanced Level)Practice--1048(Find Coins)
- C++string详解
- VC++6.0——》error LNK2001: unresolved external symbol __beginthreadex
- 实参和其对应的形参各占用独立的存储单元?
- 三值逻辑小解
- VC++6.0问题——》 'Debug/shuju1.pch': No such file or directory
- C++代码片段
- 单片机楼梯灯制作(C语言版)
- 华为练习 6 地铁最佳路径
- 我在CSDN的第一篇博客
- 从Java到C++——基本数据类型
- C++ Primer 第三章 标准库类型
- 《C++Templates》第二章-初探函数模板
- 单片机流水灯制作(C语言版)
- c++中异或运算 找不同
- C++编程->斐波那契数列模板判断实现