3 ms·
A const object can also still have mutable data. const_cast can just remove the 'const' attribute entirely, but even ignoring that "abuse" there's also the 'mut
by kllrnohj 5y ago
A const object can also still have mutable data. const_cast can just remove the 'const' attribute entirely, but even ignoring that "abuse" there's also the 'mutable' keyword which allows fields to be modifiable on const objects.
https://en.cppreference.com/w/cpp/language/cv https://en.cppreference.com/w/cpp/language/cv
- zozbot234 5y agoThe rationale for "mutable" is similar to the one for interior mutability in Rust. It's actually really hard to define what it means for something to be "constant" in a systems language, and that's why Rust did not consider deeper sorts of immutability or functional purity.
- fwsgonzo 5y agomutable is used primarily for memoization: https://en.wikipedia.org/wiki/Memoization https://en.wikipedia.org/wiki/Memoization