Constructor called instead of opAssign()
Boris Carvajal
boris2.9 at gmail.com
Sun Feb 14 08:38:49 UTC 2021
On Sunday, 14 February 2021 at 07:09:20 UTC, frame wrote:
> Although x is well initialized by A by calling opAssign(), the
> compiler doesn't care and calls the S!T ctor() on B again and
> opAssign() is ignored. Is this a bug or a rule?
It's a rule described here:
https://dlang.org/spec/struct.html#field-init
"In a constructor body ... the first instance of field assignment
is its initialization."
If you assign a second time, it will use the opAssign method.
More information about the Digitalmars-d-learn
mailing list