Default struct constructor
Paul
paultjeadriaanse at gmail.com
Wed Jan 27 22:05:20 UTC 2021
On Wednesday, 27 January 2021 at 18:00:02 UTC, Ali Çehreli wrote:
>
> struct S {
> int i;
>
> static S opCall() {
> S s;
>
> import std.random : uniform;
> s.i = uniform(1, 42);
>
> return s;
> }
>
> static S defaulted() {
> return S();
> }
> }
Does this mean opCall takes priority over default constructors
(or struct literals, I have no clue what the difference is,
semanthically or implementation wise), whilst it does not when
arguments are included?
(As https://dlang.org/spec/operatoroverloading.html states
selfdefined constructors take priority)
Thanks for the suggestion by the way, it seems Jonathan M Davis
although I hadn't noticed. This seems like a simple solution
By the way, doesnt this mean a this(){} syntax could be
implemented by treating it as syntactic sugar for opCall? I
noticed C++ also has non-argument struct constructors, so its a
bit curious to me.
More information about the Digitalmars-d
mailing list