您的位置:首页 > 其它

第六周实验报告1

2012-03-26 18:03 155 查看
#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");
}

#include<iostream>
using namespace std;
class C
{
private:
int x;
public:
C(int x){this->x = x;}
int getX()const
{return x;}
};
void main()
{
const C c(5);
cout<<c.getX();
system("pause");
}




 

 

第二种好,第二种在运算的过程中,不会改变值。使结果不会发生改变。

仔细看const在什么地方,在判断。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  system c