3 ms·
const_cast is only for removing const from references or pointers that actually refer to a non-const object. You can't declare a const variable and then modify
by gary_0 3y ago
const_cast is only for removing const from references or pointers that actually refer to a non-const object. You can't declare a const variable and then modify it with const_cast. See "Notes" at: https://en.cppreference.com/w/cpp/language/const_cast https://en.cppreference.com/w/cpp/language/const_cast
The compiler can indeed put const objects in the executable's .rodata section, which means trying to modify it at runtime will probably cause a segfault (but it's all Undefined Behavior so who knows).