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

Carl Sturtivant sturtivant at gmail.com
Sat Nov 30 14:18:32 PST 2013


The following is boiled down from a real world context. I'm using 
dmd 2.064.2 Windows. Can someone please explain what's going on.

================

struct my_integer {
     int val = 99;
     alias val this;
     //this( int n) { val = n; }
}

struct blah {
     my_integer Integer;

     this( int n) { Integer = n; }
     ref blah opAssign( int n) { Integer = n; return this; }
}

================

The constructor in blah does not compile unless the constructor 
in my_integer is uncommented. Yet the opAssign function in blah 
compiles just fine.

The error message is
  Error: cannot implicitly convert expression (n) of type int to 
my_integer
and the line causing it is blah's constructor.

This behavior did not exist with dmd 2.063.2 (Windows) --- I 
reverted to check this.



More information about the Digitalmars-d-learn mailing list