immutable and static this()
Simen kjaeraas
simen.kjaras at gmail.com
Mon Mar 21 14:27:53 PDT 2011
On Mon, 21 Mar 2011 22:27:17 +0100, teo <teo.ubuntu at yahoo.com> wrote:
> I cannot initialize immutable class members inside a static this()
> constructor. Is there any reason for that?
>
> Example:
> class Test
> {
> public immutable(int) x;
> static this()
> {
> x = 1; // Error: variable Test.x can only initialize const x
> inside constructor
> }
> }
Non-static class members require a this pointer, and thus cannot be
initialized in a static constructor. However, if that is the error
message you get, it is clearly misleading.
--
Simen
More information about the Digitalmars-d-learn
mailing list