On 8/1/2011 5:58 PM, Jonathan M Davis wrote:
On 8/1/2011 5:07 PM, Jonathan M Davis wrote:
You do get some gains from const in C++, but it's pretty much all gained
by convention. It _is_ better than just comments in that the compiler
will complain if you break the convention, forcing you to explicitly
break it (e.g. via casting or mutable), but ultimately, it doesn't
enforce much. I do believe that it enforces enough that it's worth
having, but it obviously doesn't provide the guarantees that D's const
does.
Any code at any time can modify a mutable member of a const object, without
even bothering with the nicety of a cast. The notion that C++ "supports"
logical const is without merit.
If an object isn't const, you can't call anything on it that isn't const. That
does gain you some level of safety which is enforced by the compiler.
Those "const" functions can still change the mutable members without any cast.