const_cast
doesn't take away the const-ness of a variable as defined. If you were to pass a non-const variable by reference in to a method taking a const reference like void foo(const int& x)
then you could use const_cast
to modify the value of x
within foo
, but only if the variable you actually passed in was not const in the first place.