/*
* Copyright (c) 2012, 烟台大学计算机学院
* All rights reserved.
* 作 者:庄子豪
* 完成日期:2013 年 4月5日
* 版 本 号:v1.0
*
* 输入描述:
* 问题描述:
* 程序输出:
* 问题分析:
*算法设计:
错误代码:
#include <iostream>
#include<stdlib.h>
using namespace std;
class C
{
private:
int x;
public:
C(int x){this->x=x;}
int getX(){return x;}
};
int main()
{
const C c(5);
cout<<c.getX();
return 0;
}
修改方案一
#include <iostream>
#include<stdlib.h>
using namespace std;
class C
{
private:
int x;
public:
C(int x){this->x=x;}
int getX() const {return x;}
};
int main()
{
const C c(5);
cout<<c.getX();
return 0;
}
修改方案二
#include <iostream>
#include<stdlib.h>
using namespace std;
class C
{
private:
int x;
public:
C(int x){this->x=x;}
int getX() {return x;}
};
int main()
{
C c(5);
cout<<c.getX();
return 0;
}