I do not understand copy constructors

drug drug2004 at bk.ru
Thu Aug 12 11:07:24 UTC 2021


12.08.2021 12:36, Learner пишет:

>  > It seems that there is no easy way to transition from a postblit to a
> copy constructor, no?
> 
> 
> 

You just need both const and mutable copy ctors to replace inout one:
```D
struct A {
     int[] data;
     this(ref return scope A rhs) { data = rhs.data.dup; }
     this(ref return scope const A rhs) const { data = rhs.data.dup; }
}
```

the mutable copy ctor accepts mutable data and the const copy ctor 
accepts const and immutable data


More information about the Digitalmars-d-learn mailing list