Concerns about struct initialization
Johannes Loher
johannes.loher at fg4f.de
Sat Dec 22 09:05:49 UTC 2018
On Saturday, 22 December 2018 at 08:53:20 UTC, Dru wrote:
> 1)
> would like to override default copy initialization
In order to do this, you need to use a postblit
(https://dlang.org/spec/struct.html#struct-postblit):
```
struct A {
this(this) {
writeln("postblit called");
}
}
void main() {
A a;
A b = a; // prints "postblit called"
}
```
See also DIP1018
(https://github.com/dlang/DIPs/blob/07da1f2cabc8b1bc3ad66034598a133e5ad13356/DIPs/DIP1018.md) which proposes that we switch to regular copy constructors for this.
More information about the Digitalmars-d
mailing list