alias this leads to compilation error in one of two similar contexts

Kenji Hara k.hara.pg at gmail.com
Sun Dec 1 21:32:30 PST 2013


On Saturday, 30 November 2013 at 22:28:14 UTC, Carl Sturtivant 
wrote:
>
> I just confirmed the same behavior on Ubuntu amd64. dmd 2.063.2 
> compiles the example and dmd 2.064.2 produces the same error as 
> the Windows 32 bit version.

This is intended behavior change from 2.064.

http://dlang.org/class#field-init

struct my_integer {
     int val = 99;
     alias val this;
}
void test() {
   //my_interger num = 1;  // NG
     my_interger num = my_interger(1);  // OK
     // 'alias this' has no effect for object initialization
}
struct blah {
     my_integer num;

     this(int n) {
       //num = n;  // also NG, my_integer cannot *initialize* by 
int value
         num = my_interger(n);  // OK
     }
}

Kenji Hara


More information about the Digitalmars-d-learn mailing list