I do not understand copy constructors

Paul Backus snarwin at gmail.com
Fri Aug 13 21:59:02 UTC 2021


On Friday, 13 August 2021 at 21:34:29 UTC, Steven Schveighoffer 
wrote:
> But for constructors it's not the same. Essentially because 
> constructors have different rules for what they can do with 
> their inputs (the inout `this` parameter can be assigned to for 
> the member's first assignment).
>
> What I was trying to say (poorly) is that inside the inout copy 
> ctor, you can actually call the const `A` copy constructor with 
> an input of the other `inout A`. You just can't call it on the 
> member (or assign it to the member), because that would allow 
> some bad things to happen in some cases.

Thanks; the special treatment of `this` is the part I was missing.

As far as I can tell there is no mention in the language spec of 
how this works. Probably worth documenting.


More information about the Digitalmars-d-learn mailing list