Struct copy constructor with inout

Paul Backus snarwin at gmail.com
Tue Nov 14 16:51:07 UTC 2023


On Tuesday, 14 November 2023 at 16:39:42 UTC, dhs wrote:
> Does this "const S2" then get implicitly converted to "S2", 
> before being assigned to "ss2"? I tried adding an opAssign() to 
> S2 - it's not getting called. So I'm not sure what is actually 
> going on here.

There's no assignment. The value is constructed in-place, in 
`ss2`'s memory.

The reason the compiler allows you to construct a `const(S2)` 
value inside of an `S2` variable is that `const(S2)` implicitly 
converts to `S2`.


More information about the Digitalmars-d-learn mailing list