← Back to team overview

kicad-developers team mailing list archive

Re: Casting away constness

 

On Sun, Apr 27, 2014 at 02:03:57PM -0600, Matthew Brigdan wrote:
> A const member function in c++ is guaranteed not to alter the object
> it belongs to when called. It does not have to return a constant
> value, or anything like that. As far as I can tell, there is not
> "casting away" of constness

Yes, the meaning of constness changed in C++, together with the
introduction of the mutable keyword. I was confusion an old behaviour.

The new const has more of a 'failsafe' meaning that a permission to
optimize (like pure functions).

Before:
A const method can't change a member variable and can't allow the
returned value(s) to change the object (even indirectly)

Now:
A const method can't change a member variable and can't allow the
returned value(s) to change directly the object. Furthermore it can do
whatever it wants with mutable members.

Pretty ugly and IMHO an hack, but that's how it's specified.


-- 
Lorenzo Marcantonio
Logos Srl


References