Does D support dynamically allocated multi-dimensional arrays?

Seth Hoenig seth.a.hoenig at gmail.com
Sun Aug 15 19:39:43 PDT 2010


Awesome, that worked.
And thanks, I wasn't aware of d.learn.



On Sun, Aug 15, 2010 at 9:33 PM, Jonathan M Davis <jmdavisprog at gmail.com>wrote:

> On Sunday 15 August 2010 19:20:12 Seth Hoenig wrote:
> > What I really want is something like this:
> >
> > auto s = args[1];
> > auto t = args[2];
> > auto d = new int[s.length][t.length];
> >
> > but the compiler complains with the error: Error: Integer constant
> > expression expected instead of s.length
> >
> > So then I try to fudge it with something like:
> >
> > auto d = new int[][t.length];
> > d.length = s.length;
> >
> > But then accessing elements of d throws an exception:
> > core.exception.RangeError at Lev(7): Range violation
> >
> > Soo.. how am I supposed to make a matrix when I don't know the dimensions
> > at compile time?
>
> Oh, and questions like this are generally supposed to go on the D.Learn
> list.
> This list is more for discussing language features and the direction of the
> language rather than asking and answering questions about how to use D.
>
> - Jonathan M Davis
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20100815/f7732292/attachment.html>


More information about the Digitalmars-d mailing list