自考新教材-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;
}

运行结果:

原文地址:https://www.cnblogs.com/duanqibo/p/12270163.html