Why D const is annoying

Michel Fortin michel.fortin at michelf.com
Wed May 2 08:59:10 PDT 2012


On 2012-05-02 15:13:43 +0000, "Mehrdad" <wfunction at hotmail.com> said:

> Yes, 'const' is part of the interface.
> 
> The trouble is that when you make it part of the interface, you're 
> making the assumption that **no one** who derives from your class will 
> need mutable state.
> 
> How can you ever guarantee that?

When you're making the object 'const', you're not making the assumption 
that no one who derives from this class need mutable state. What you're 
doing is asserting that bits belonging to this object needs to be 
'const' to preserve sequential consistency across threads or for other 
reasons. If the derived class casts away const, it breaks that contract.

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/



More information about the Digitalmars-d mailing list