您的位置:首页 > 其它

第6周实验报告1

2012-03-27 15:39 148 查看
实验目的:学会常对象

实验内容:编码改错

* 程序头部注释开始

* 程序的版权和版本声明部分

* 烟台大学计算机学院学生

* 文件名称:         编码改错                   

* 作    者:          胡斌                

* 完成日期:  2012 年 3月27  日

* 版本号:     v1.0    

* 程序头部的注释结束(此处也删除了斜杠)

#include <iostream>

using namespace std;

class C

{

private:

 int x;

 public:

 C(int x){this->x = x;}

 int getX() const{return x;} //把成员函数改成const型

};

void main()

{

 const C c(5);

 cout<<c.getX();

 system("pause");

}

 

#include <iostream>

using namespace std;

class C

{

private:

 int x;

 public:

 C(int x){this->x = x;}

 int getX() {return x;}

};

void main()

{

  C c(5);//把对象改成一般型

 cout<<c.getX();

 system("pause");

}

 



我比较喜欢第一种改法,可以让我熟悉常对象。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  system c