3 ms·
So, to summarize the article in the link, 1. I don't like the syntax for const [fair enough] 2. I want to have an object that obeys someone's const'ing of it
by CountSessine 11y ago
So, to summarize the article in the link,
1. I don't like the syntax for const [fair enough]
2. I want to have an object that obeys someone's const'ing of it but still be able to mess around with its internal state (like for logging, data caching, or intermediate calculations), and there's no way of doing that...
3. ...except that there is - it's the mutable keyword, but that's bad because other programmers other than me who are using it to modify 'const'ed classes (for logging, data caching, or intermediate calculations) can't be trusted.
Seriously - that's what he says:
One in particular annoys me because my programs often needed to be optimized for speed. [because I'm 'leet] This is that a method which is declared ‘const’ cannot even make changes to the hidden parts of its object that would not make any changes that would be apparent from the outside
...
In later versions of C++, the ‘mutable’ keyword was added which enables ‘const’ to be overridden for this purpose but it totally relies on trusting the programmer to only use it for that purpose so
!!!