Initialising multidimensional dynamic arrays
Steven Schveighoffer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Oct 1 05:29:44 PDT 2014
On 10/1/14 3:13 AM, Mike James wrote:
> Hi Steve,
>
> It's true that his code initialises an array of arrays - but my array is
> an array of structs containing a dynamic array.
>
> Regards, -=mike=-
Ah, ok.
There is no trivial way to do it. Unlike C++, struct default ctors
cannot be overridden.
I see your question has been answered, but I would just tweak it a bit:
foreach(ref m; mda) m.data = new short[y];
Only reason for that is, setting length will call some specialized
function which eventually ends up doing exactly the same thing. The
above is clearer and more correct IMO.
-Steve
More information about the Digitalmars-d-learn
mailing list