您的位置:首页 > 其它

第六周 阅读程序二

2015-04-09 13:55 225 查看
问题及代码:

/*

* Copyright (c) 2015, 烟台大学计算机学院

* All rights reserved.

* 文件名称:read.cpp

* 作 者:李楠

* 完成日期:2015年4月8日

* 版 本 号:v1.0

*

* 问题描述:阅读程序

* 输入描述:略

* 程序输出:略

*/

#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;

}

运行结果:



知识点总结:

注意析构函数的执行~!

学习心得:

我感觉有时候很容易把析构函数的执行忘记了……
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: