logoalt Hacker News

wtetznerlast Monday at 11:08 AM1 replyview on HN

> members of a const struct are also const.

Yes, but if your struct contains references, the constness doesn't apply to what those references point to. In Rust it does.


Replies

mgaunardlast Monday at 11:35 AM

For pointers, const only affects whether you can re-set it to point to something else, not the pointee.

Nothing prevents you from building a smart pointer with those semantics though, std::indirect is an example of this (arguably closer to Rust's Box).

show 1 reply