Why does multidimensional arrays not allocate properly?
rikki cattermole via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Jan 22 00:07:26 PST 2017
On 22/01/2017 9:05 PM, Jot wrote:
> auto x = new int[][](n,m);
>
> But one cannot freely assign anywhere in x:
>
> x[3,6] = 4 crashes.
>
> I, can, of course, convert everything to a linear matrix and index by
> i+w*j, but what's the point of having multidimensional matrices in D if
> they don't allocate them fully?
It does allocate them fully, you're indexing them wrong.
void main() {
auto x = new int[][](1, 2);
x[0][1] = 3;
}
More information about the Digitalmars-d-learn
mailing list