mutable 关键字
刚才看了一段小程序,发现这个关键字,但是不知道什么作用。
原来是指用此关键字声明的变量是一个易变的变量,即使在const方法中也可以改变类中声明为mutable的属性。
原来是指用此关键字声明的变量是一个易变的变量,即使在const方法中也可以改变类中声明为mutable的属性。
class Screen {
private:
mutable int test ;
mutable int a ;
public:
int test2() const
{ int e = 0 ; ++e ;
a = ++test + 100 ; return test ;
}
} ;
这是没有问题的private:
mutable int test ;
mutable int a ;
public:
int test2() const
{ int e = 0 ; ++e ;
a = ++test + 100 ; return test ;
}
} ;