Struct Initialization syntax

Dukc ajieskola at gmail.com
Tue Jul 24 13:13:16 UTC 2018


On Tuesday, 24 July 2018 at 12:37:21 UTC, Cym13 wrote:
> That argument sounds quite dangerous to me, especially since my 
> experience is on the contrary that constructor arguments are 
> often named the same as the attribute they refer to. And what 
> of mixed cases? I really wouldn't rely on anything like naming 
> conventions for something like that.

I was going to ask that how can they be named the same since the 
argument would then shadow the member, but then I realized that 
this works:

struct S
{   int a;
     int b;

     this(int a, int b)
     {   this.a = a;
         this.b = b;
     }
}

Yes, you are right.


More information about the Digitalmars-d mailing list