Why would an initialised struct pointer field be null in the struct's destructor?
Eduard Staniloiu via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun May 21 05:26:26 PDT 2017
On Saturday, 20 May 2017 at 10:48:54 UTC, Gary Willoughby wrote:
Looks like you would want to use emplace [0] here.
> public this(int n)
> {
> this._data = (cast(Foo*) calloc(n, Foo.sizeof))[0 .. n];
>
> foreach(ref element; this._data)
> {
> auto tmp = Foo(1);
> element = tmp;
> }
> }
Cheers,
Eduard
[0] - https://dlang.org/phobos/std_conv.html#.emplace.3
More information about the Digitalmars-d-learn
mailing list