4 ms·
This explanation of const sounds much like Java's final, but not like C++'s const guarantees, which enable you to guarantee nobody downstream of a const modifie
by cbetti 9y ago
This explanation of const sounds much like Java's final, but not like C++'s const guarantees, which enable you to guarantee nobody downstream of a const modified reference will be allowed to perform a write operation through that reference.
You cannot get around that behavior by assigning the reference to a non-const copy. That isn't allowed.
- pcwalton 9y agoBut if some other code gets a non-const reference to an object via another pointer path, that code can mutate the object, even though const pointers to that object may exist. In Rust, this is not the case. That difference severely weakens the meaning of the const property in C++.
- frankzinger 9y agoSee my comment below for how to prevent this: https://news.ycombinator.com/item?id=16550209 https://news.ycombinator.com/item?id=16550209