Dynamic twodimensial array

data pulverizer data.pulverizer at gmail.com
Tue Mar 31 22:04:29 UTC 2020


On Tuesday, 31 March 2020 at 21:39:30 UTC, Quantium wrote:
> I know that to create a dynamic array:
> int[] m = new int[a];
> where a is a variable.
> And if I need a twodimensial array, code
> int[][] m = new int[a][b];
> where a and b are variables doesn't work. I used dmd compiler, 
> it says: "Cannot read b at compile time" but there is new int, 
> so array should be dynamic. Where is the problem in my code?

/* Try */
auto m = new int[][](a, b);

A few lines below your query is the answer in a blog 
(https://github.com/tastyminerals/tasty-blog/blob/master/_posts/2020-03-22-multidimensional_arrays_in_d.md). Also if you haven't read the "Programming in D" book (https://ddili.org/ders/d.en/index.html) please do, it's very good.



More information about the Digitalmars-d-learn mailing list