On Thu, 23 May 2013 10:16:13 -0400, Iain Buclaw <[email protected]> wrote:
On 23 May 2013 14:52, Steven Schveighoffer <[email protected]> wrote:
Adding an initializer simply changes the default value from 0 to
whatever
you want. It's quite consistent IMO.
Don't think it makes sense in non-POD structs...
Haven't tested, but is this an error?
struct S
{
const int;
this (int x)
{
this.x = x; // here
}
}
S(5);
Well, since you didn't name the member, it didn't compile right off :)
But after I fixed that, it does compile, both on 2.061 and the beta.
However, there is definitely a bug somewhere, this compiles:
struct S
{
const int x;
int y;
this (int x)
{
y = this.x;
writeln(this.y);
this.x = x;
writeln(this.x);
this.x = 0;
writeln(this.x);
}
}
outputs:
0
5
0
Seems like const qualifier for members is simply ignored inside the ctor,
it should only be ignored until it is set, or until it is used.
-Steve