How to allocate arrays of objects?
cy via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Feb 10 20:31:12 PST 2016
On Thursday, 11 February 2016 at 04:07:18 UTC, cy wrote:
> A[] as = new A[2];
> assert(as.length==2);
> as[0].stuff = 42;
Oh, I get it. `as` is an array of 2 pointers to A objects, both
pointers set to null. So I need to say like:
as[0..$] = new A();
before accessing .stuff on as[0].
Still no clue why it segfaulted on the allocation though, rather
than the statement with the null dereference. Hidden optimization?
More information about the Digitalmars-d-learn
mailing list