Consider the following C ++ 03 program:
#include <iostream> struct T { mutable int x; T() : x(0) {} }; void bar(int& x) { x = 42; } void foo(const T& t) { bar(const_cast<int&>(tx)); } int main() { T t; foo(t); std::cout << tx << '\n'; }
It works , but is it safe?
I only change the mutable field, but by removing its const context, I am completely nervous.
source share