第六周 阅读程序二
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;
}
运行结果:
知识点总结:
注意析构函数的执行~!
学习心得:
我感觉有时候很容易把析构函数的执行忘记了……
/*
* 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;
}
运行结果:
知识点总结:
注意析构函数的执行~!
学习心得:
我感觉有时候很容易把析构函数的执行忘记了……
相关文章推荐
- 第六周项目零:阅读程序(4):结构函数和析构函数
- 第六周项目零:阅读程序(1):结构函数和析构函数
- 第六周程序阅读1
- 第六周程序阅读(2)
- 第六周程序阅读(1)
- 第六周阅读程序—a
- 第六周项目4.1 成员函数 友元函数和一般函数有区别——阅读程序,体会注释中的说明
- 第六周项目四:成员函数、友元函数和一般函数有区别(阅读程序)
- 第六周 阅读程序一
- 第六周程序阅读(4)
- 第六周项目零:阅读程序(2):结构函数和析构函数
- 第六周——程序阅读(五)
- 第六周——程序阅读(四)
- 第六周 程序阅读三
- 第六周程序阅读三
- 第六周项目零:阅读程序(5):结构函数和析构函数,对象的赋值
- 第六周——程序阅读(三)
- 第六周项目零:阅读程序(3):结构函数和析构函数
- 第六周程序阅读4
- 第六周项目程序阅读(5)