Initialising multidimensional dynamic arrays
Mike James via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Oct 1 00:45:48 PDT 2014
On Tuesday, 30 September 2014 at 15:57:58 UTC, Mike James wrote:
> Hi,
>
> How do I initialise a dynamic array of dynamic arrays?
>
> struct MyData {
> SysTime stamp;
> short[] data;
>
> this(size_t size) {
> data = new short[size];
> }
> }
>
> MyDataArray mda;
>
> how to initialise mda?
>
> mda = new MyDataArray ?
>
> Thanks.
>
> Regards, -=mike=-
I think I've found a way...
struct MyData {
SysTime stamp;
short[] data;
this(size_t size) {
data = new short[size];
}
}
MyDataArray[] mda; <--- sorry, missing the []s in the original
question...
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?
Regards, -=mike=-
More information about the Digitalmars-d-learn
mailing list