More on immutable
Steven Schveighoffer
schveiguy at yahoo.com
Mon Mar 8 06:28:52 PST 2010
On Mon, 08 Mar 2010 09:08:26 -0500, bearophile <bearophileHUGS at lycos.com>
wrote:
> I am trying to learn more about the usage of immutable. This is a little
> D2 program:
>
>
> immutable class S {
> static int x;
> static this() {
> S.x = 10;
> }
> }
> void main() {}
>
>
> The compiler outputs:
> test.d(3): Error: function test2.S._staticCtor1 without 'this' cannot be
> const/immutable
>
> Can you tell me what's wrong or how I can fix it?
There was a discussion on D.learn in December of last lear that resulted
in this bug being filed:
http://d.puremagic.com/issues/show_bug.cgi?id=3598
Note that even if static functions were allowed in immutable
classes/structs, the static field members will still be tagged as
immutable, so your example shouldn't compile.
-Steve
More information about the Digitalmars-d-learn
mailing list