3 ms·
No, the caller is saying that the callee isn't permitted to change the value! That's what const means. No promise is made about the actual object itself. There'
by to3m 13y ago
No, the caller is saying that the callee isn't permitted to change the value! That's what const means. No promise is made about the actual object itself. There's no general way to specify that in C++.
This isn't so much an issue for functions, where the caller is stopped while the callee runs, but it needs to be borne in mind for longer-lived objects that take const references - or, indeed, const pointers - to objects that have longer lifetimes again. (I don't think multithreading need be introduced for this to be an issue.)
There's quite a difference between an object that could change and one that won't, if you're considering caching values across method calls, or setting up the referring object based on the referred object's current state, etc.
- dllthomas 13y agoRight, multithreading is needed for it to be an issue with functions, not with containers.
- alexchamberlain 13y agoOk, I know what the spec says, but it is utterly rediculous to expect people to write code in which parameters are allowed to change in an undefined way.