violation of const variable using a pointer c++ -
Why do I have permission to change a single console value without errors?
void foo (long * A) {* A = 50; } Int _tmain (int argc, _TCHAR * argv []) {const tall a = 7; Const long * b = & amp; A; Fu ((* long *) b); // now the value of one 50}
You / Em>.
When you wrote that the C-style cast, you have disabled the check. If you wrote it:
foo (static_cast & lt; tall *> (b)); or just
foo (b); So your program does not compile.
To allow you to perform specialist magic, you can still write:
foo (const_cast & lt; long *> (b)); But still it is the responsibility of your to ensure that you do not use it for evil, as evil in your example.
Comments
Post a Comment