mutable int test; file://这里处理!
};
2)强制转换:const_cast
class a
{
public:
a(int i=0):test(i) { }
void setvalue(int i)const
{ const_cast <int>(test)=i; }//这里处理!
private:
int test;
};
3)灵活的指针:int*
class a
{
public:
a(int i=0):test(i) { }
void setvalue(int i)const
{ *test=i; }
private:
int* test; file://这里处理!
};
4)未定义的处理
class a
{
public:
a(int i=0):test(i) { }
void setvalue(int i)const
{ int *p=(int*)&test; *p=i; }//这里处理!
private:
int test;
};
注意,这里虽然说可以这样修改,但结果是未定义的,避免使用!
5)内部处理:this指针
class a
{
public:
a(int i=0):test(i) { }
void setvalue(int i)const