自考新教材-p146_4(2)

源程序:

#include <iostream>
using namespace std;

class CTest
{
private:
int n;
public:
CTest()
{
n = 1;
}
int GetValue() const
{
return n;
}
int GetValue()
{
return 2 * n;
}
};
int main()
{
const CTest objTest1;
CTest objTest2;
cout << objTest1.GetValue() << "," << objTest2.GetValue();
system("pause");
return 1;
}

运行结果:

 

posted @ 2020-02-06 20:12  bobo哥  阅读(138)  评论(0编辑  收藏  举报