Static attributes aren' immutable

Pelle Månsson pelle.mansson at
Fri Mar 5 12:07:53 PST 2010

On 03/05/2010 07:50 PM, bearophile wrote:
> div0:
>> putting it in Foo simply puts it in a namespace.<
> So my (wrong) idea of immutable applied to a struct was that every thing in such namespace becomes immutable (I think this is a bit more intuitive).
> What do you think of modifying D2 so in a situation like the one I've shown even static arguments become const/immutable? Can this cause troubles to other things?
> Thank you to you and Lars T. Kyllingstad for the answers.
> Bye,
> bearophile

Immutability (somewhat) guarantees the value will never ever change. The 
static attribute could be changed by a non-immutable instance, and can 
therefore not be immutable. It could be const for the immutable 
instance, but I don't see the gains from it.

I do, however, see the gains from not being able to access the static 
members through an instance.

More information about the Digitalmars-d-learn mailing list