Although not appreciated, C ++ provides a "Backdoor" that can be used to violate your own rules, just like dirty pointer tricks. In any case, you can easily do this using the cast version of the "This" pointer:
class A (){
int x;
public:
void func () const {
A* ptr = const_cast<A*> (this);
ptr->x= 10;
}
}
source
share