Re: Dynamic twodimensial array

2020-03-31 Thread data pulverizer via Digitalmars-d-learn

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.




Dynamic twodimensial array

2020-03-31 Thread Quantium via Digitalmars-d-learn

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?