Re: initializing struct containing user defined type

2022-02-18 Thread user1234--- via Digitalmars-d-learn
On Friday, 18 February 2022 at 23:46:51 UTC, forkit wrote: On Friday, 18 February 2022 at 16:45:24 UTC, Ali Çehreli wrote: ... I think that syntax will be obviated when D will have named arguments. Ali Huh? D doesn't have named arguments, already? That's an important component for safe(r)

Re: initializing struct containing user defined type

2022-02-18 Thread forkit via Digitalmars-d-learn
On Friday, 18 February 2022 at 16:45:24 UTC, Ali Çehreli wrote: ... I think that syntax will be obviated when D will have named arguments. Ali Huh? D doesn't have named arguments, already? That's an important component for safe(r) programming. Do you know if there is a DIP for this, and i

Re: initializing struct containing user defined type

2022-02-18 Thread Ali Çehreli via Digitalmars-d-learn
On 2/18/22 12:16, Salih Dincer wrote: >// x.writeln(y); // 2.087 >"D Compiler v".writeln(__VERSION__/1000.0); > ``` > I'm using v2.087 but because of @disable this line doesn't work: ```// > x.writeln(y); // 2.087``` > > Why? Can you give an explanation for this? This is not related to s

Re: initializing struct containing user defined type

2022-02-18 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 18 February 2022 at 16:45:24 UTC, Ali Çehreli wrote: On 2/18/22 07:01, kdevel wrote: > Error: struct `B` has constructors, cannot use `{ initializers }`, > use `B( initializers )` instead > > What is the rationale behind that? I mean: If the compiler exactly > sees what the pr

Re: initializing struct containing user defined type

2022-02-18 Thread Ali Çehreli via Digitalmars-d-learn
On 2/18/22 07:01, kdevel wrote: > Error: struct `B` has constructors, cannot use `{ initializers }`, > use `B( initializers )` instead > > What is the rationale behind that? I mean: If the compiler exactly > sees what the program author intends to express why does it force the > author to

Re: initializing struct containing user defined type

2022-02-18 Thread kdevel via Digitalmars-d-learn
On Friday, 18 February 2022 at 14:37:25 UTC, Ali Çehreli wrote: On 2/18/22 06:19, kdevel wrote: > // auto b3 = B ("A", "B"); // Error: cannot implicitly convert > // expression `"A"` of type `string` to `A` Yeah, D disallows some implicit conversions. Adding a constructor to B will m

Re: initializing struct containing user defined type

2022-02-18 Thread Ali Çehreli via Digitalmars-d-learn
On 2/18/22 06:19, kdevel wrote: > // auto b3 = B ("A", "B"); // Error: cannot implicitly convert > // expression `"A"` of type `string` to `A` Yeah, D disallows some implicit conversions. Adding a constructor to B will make it work: this(string as, string bs) { this.a = A(as);