Initialising multidimensional dynamic arrays
ketmar via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Oct 1 01:07:54 PDT 2014
On Wed, 01 Oct 2014 07:45:48 +0000
Mike James via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com>
wrote:
> so in the constructor...
>
> this(size_t x, size_t y) {
> mda = new MyDataArray[](x);
> foreach(n, _; mda) mda[n].data.length = y;
> }
>
> Is there a simpler way?
sorry, but no. btw, if MyDataArray is struct, you should do this:
foreach (ref m; mda) m.data.length = y;
or even this:
foreach (ref m; mda = new MyDataArray[](x)) m.data.length = x;
the thing is that without 'ref' you operates on the local copy, not on
the real array element.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20141001/dcab074a/attachment.sig>
More information about the Digitalmars-d-learn
mailing list