alias this and initialisation

Ali Çehreli acehreli at yahoo.com
Mon May 25 07:36:29 UTC 2020


On 5/24/20 6:35 PM, Danni Coy wrote:> can anybody tell me why
 >
 > struct S
 > {
 >      int x;
 >      alias x this;
 > }
 >
 > void test()
 > {
 >      S s;
 >      s = 8; // this works
 >      S s = 8 // but this does not?
 > }

alias this is for implicit conversion, which requires an object to 
convert from. The second case above is about constructing an object.

That's probably why it works that way.

Ali



More information about the Digitalmars-d-learn mailing list