C++中析构函数的问题
时间:2011-12-11
来源:互联网
作者: zhaokankan 发布时间: 2011-12-11
作者: Demon__Hunter 发布时间: 2011-12-11
由于析构会回收资源
程序退出了。。。资源没有回收,,是很糟糕的方式。。
比如:
作者: seujh2010 发布时间: 2011-12-11
exit 会退出整个程序
由于析构会回收资源
程序退出了。。。资源没有回收,,是很糟糕的方式。。
比如:
作者: zhaokankan 发布时间: 2011-12-11
问题是,在析构函数里面回收资源,可以让程序在不退出运行的情况下回收资源。试想想,如果一个程序中有10个类,每个类中都写了exit,那么基本上可以说这个程序很难正确地工作,也就是说事情还没做好,程序就退出了。
作者: pathuang68 发布时间: 2011-12-11
作者: zhujian888 发布时间: 2011-12-11
Performs complete C library termination procedures, terminates the process, and exits with the supplied status code.
结束整个程序。
C/C++ code
/* EXITER.C: This program prompts the user for a yes * or no and returns an exit code of 1 if the * user answers Y or y; otherwise it returns 0. The * error code could be tested in a batch file. */ #include <conio.h> #include <stdlib.h> void main( void ) { int ch; _cputs( "Yes or no? " ); ch = _getch(); _cputs( "\r\n" ); if( toupper( ch ) == 'Y' ) exit( 1 ); else exit( 0 ); }根据参数的不同判断程序是否为正常终止。
作者: cxxer 发布时间: 2011-12-11
作者: bsr_nj 发布时间: 2011-12-11

作者: gold_water 发布时间: 2011-12-11
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28