I do not understand copy constructors

drug drug2004 at bk.ru
Thu Aug 12 12:00:36 UTC 2021


12.08.2021 14:32, Paul Backus пишет:
> 
> This is not true. Qualifying the ctor as `inout` works fine: 
> https://run.dlang.io/is/Kpzp5M
> 
> The problem in this example is that `.dup` always returns a mutable 
> array, even if the array being copied is `inout`. The solution is to 
> cast the copy back to the original type:
> 
> ```d
> this(ref return scope inout A rhs) inout
> {
>      data = cast(typeof(rhs.data)) rhs.data.dup;
> }
> ```

Yes, it's not true. I forgot that ctors are special in contrast to 
regular methods and can modify the aggregate they belong to even if the 
ctor has const/immutable/inout qualifier.


More information about the Digitalmars-d-learn mailing list