Struct initialization has no effect or error?
    Mike Parker 
    aldacron at gmail.com
       
    Thu Oct  3 05:48:46 UTC 2019
    
    
  
On Thursday, 3 October 2019 at 04:57:44 UTC, mipri wrote:
> On Thursday, 3 October 2019 at 04:33:26 UTC, Brett wrote:
>> I was trying to avoid such things since X is quite long in 
>> name. Not a huge deal... and I do not like the syntax because 
>> it looks like a constructor call.
>
> It is a constructor call, though. You can define your own as 
> well:
Technically it's a struct literal. It's only a constructor if you 
define one, in which case struct literals no longer work. E.g.,
struct Foo {
     int x;
     this(int a, int b) { x = a + b; }
}
Without the constructor, the literal Foo(10) would be valid, but 
with the constructor you'll get a compiler error.
    
    
More information about the Digitalmars-d-learn
mailing list