第六周 课后实践:阅读程序
来源:互联网 发布:2015年老龄化数据 编辑:程序博客网 时间:2024/05/21 11:18
(4)问题及代码:
#include <iostream>using namespace std;class example{public: example() { cout<<"Default Constructing! "<<endl; } example(int n) { i=n; cout<<"Constructing: "<<i<<endl; } ~example() { cout <<"Destructing: "<<i<<endl; } int get_i() { return i; }private: int i;};int sqr_it(example o){ return o.get_i()* o.get_i();}int main(){ example x(10); cout<<x.get_i()<<endl; cout<<sqr_it(x)<<endl; return 0;}
运行结果:
(5)问题及代码:
#include <iostream>using namespace std;class AA{public: AA(int i,int j) { A=i; B=j; cout<<"Constructor\n"; } AA(AA &obj) { A=obj.A+1; B=obj.B+2; cout<<"Copy_Constructor\n"; } ~AA() { cout<<"Destructor\n"; } void print() { cout<<"A="<<A<<",B="<<B<<endl; }private: int A,B;};int main(){ AA a1(2,3); AA a2(a1); a2.print(); AA *pa=new AA(5,6); pa->print(); delete pa; return 0;}
运行结果:
0 0
- 第六周 课后实践--阅读程序
- 第六周课后实践:阅读程序
- 第六周 课后实践:阅读程序
- 第六周 课后实践:阅读程序
- 第二周课后实践-阅读程序
- 第二周课后实践--阅读程序
- 第二周课后实践阅读程序
- 第二周--课后实践:阅读程序
- 第二周 课后实践 程序阅读
- 第二周 课后实践 阅读程序2
- 第三周课后实践-阅读程序
- 第三周 课后实践 阅读程序
- 第三周课后实践 阅读程序
- 第三周 课后实践--阅读程序
- 第三周课后实践:阅读程序
- 第五周课后实践:阅读程序
- 第八周课后实践:阅读程序
- 第八周 课后实践:阅读程序
- 图像操作的形态学处理MATLAB
- 第六周项目1 深复制体验
- android中的线程(二上)
- 第六周阅读程序2:构造函数与析构函数
- 省选模版复习——FFT
- 第六周 课后实践:阅读程序
- 第六周 程序阅读-深复制、友元、类模板(3)
- 2-6-2 我的数组类
- 第6周项目1-深复制体验(2)
- hadoop与memcache的区别
- 人数不定的工资类-动态分配空间
- 关于servlet 和jsp 中的 session对象
- 第六周项目:深复制体验
- Sorting Problem I NOJ1870 水 冒泡排序