SDUT-2672 3-3 构造函数的调用(高级)
来源:互联网 发布:大数据在博客 编辑:程序博客网 时间:2024/05/22 12:41
3-3 构造函数的调用(高级)
Time Limit: 1000MS Memory Limit: 65536KB
SubmitStatistic
Problem Description
通过本题目的练习可以掌握创建普通对象、创建对象数组和动态创建和析构对象时调用构造函数和析构函数的时机;
要求创建一个类A;类中仅包含构造函数和析构函数,按照程序的输出写出类的定义和主函数main中的代码。
Input
无
Output
输出共有11行数据,分别如示例输出所示
Example Input
无
Example Output
----begin main---constructing an object of Aconstructing an object of ADestructing an object of A*******constructing an object of Aconstructing an object of A----end main---Destructing an object of ADestructing an object of ADestructing an object of A
Hint
①如果在函数中定义了一个对象,当函数调用结束时,释放对象前自动执行析构函数。② static 局部对象在函数调用结束时,包含的对象不会被释放,只在main函数结束或调用exit函数时,才调用static局部对象的析构函数。 ③如果定义了一个全局对象,则在程序的流程离开其作用域时(如main函数结束,或exit语句),调用该全局对象的析构函数。④ 如果用new运算符动态地建立了一个对象,当用delete 运算符释放对象时,先调用该全局对象的析构函数
#include <iostream>using namespace std;class L{public: L(); ~L();};L::L(){ cout<<"constructing an object of A"<<endl;}L::~L(){ cout<<"Destructing an object of A"<<endl;}int main(){ cout<<"----begin main---"<<endl; L d1; L *d2; d2=new L; delete d2; cout<<"*******"<<endl; L d3;L d4; cout<<"----end main---"<<endl; return 0;}
阅读全文
0 0
- SDUT-2672 3-3 构造函数的调用(高级)
- sdut 3-3 构造函数的调用(高级)
- 3-3 构造函数的调用(高级)--SDUT
- sdut 3-2 构造函数的调用
- 3-2 构造函数的调用-SDUT
- SDUT-2671 3-2 构造函数的调用
- 3-3 构造函数的调用(高级)
- 3-3 构造函数的调用(高级)
- 3-3 构造函数的调用(高级)
- 3-3 构造函数的调用(高级)
- 3-3 构造函数的调用(高级)
- 3-3 构造函数的调用(高级)
- 3-3 构造函数的调用(高级)
- 3-3 构造函数的调用(高级)
- 3-3 构造函数的调用(高级)
- 3-3 构造函数的调用(高级)
- 3-3 构造函数的调用(高级)
- 3-3 构造函数的调用(高级)
- Java四种引用包括强引用,软引用,弱引用,虚引用。 强引用: 只要引用存在,垃圾回收器永远不会回收 Object obj = new Object(); //可直接通过obj取得对应的对象
- visual c++ 编译报错:symbol _WinMain@16
- 有关数组与向量对比的小作业
- lombok介绍及使用方法
- LOMO+XQDA(2015CVPR)
- SDUT-2672 3-3 构造函数的调用(高级)
- 【codevs 1154】能量项链
- Spring+Hibernate动态切换数据源以及失败解决方案
- input框的class属性为form-control,怎么去调边框和阴影
- Android发送POST请求上传图片后台解析本地一片黑问题
- easyui根据部门业务员显示可用的日期
- 关于QTableWidget常见错误
- golang json
- Spring Cloud构建微服务架构:Hystrix监控面板【Dalston版】