const int n = 100;//定义一个常量 必须初始化
const int & ref = n;//引用一个const常量
const int *p;// *p 是常量
const int & ref = n;//引用一个const常量
const int *p;// *p 是常量
int *const p2;//p2是常量 不能指向其它变量
class Test
{
public:
Test(int x) : x_(x)
{
}
int Get() const
{
//x_++; 不能修改数对象状态
return x_;
}
void Output() const
{
printf("\nOutput()\n");
outPutTimes_++;
}
int GetOutputTimes() const
{
return outPutTimes_;
}
private:
int x_;
mutable int outPutTimes_;
};