digitalmars.D.learn - Dynamic twodimensial array
- Quantium (8/8) Mar 31 2020 I know that to create a dynamic array:
- data pulverizer (5/13) Mar 31 2020 /* Try */
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?
Mar 31 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-multidimensio al_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.
Mar 31 2020