第六周 阅读程序二

来源:互联网 发布:mysql error 1045 编辑:程序博客网 时间:2024/05/21 19:43

问题及代码:

/*
* 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;
}

运行结果:


知识点总结:
注意析构函数的执行~!

学习心得:
我感觉有时候很容易把析构函数的执行忘记了……

0 0
原创粉丝点击