variable x cannot be read at compile time - how to get around this?

Sergey via Digitalmars-d digitalmars-d at puremagic.com
Thu Nov 13 19:39:10 PST 2014


On Thursday, 13 November 2014 at 14:27:32 UTC, Steven 
Schveighoffer wrote:
> On 11/13/14 2:08 AM, Sergey wrote:
>>   Hello everyone!
>>
>> I need to create a two-dimensional array in this way, for 
>> example:
>>
>> auto x = 10;
>> auto y = 10;
>> auto some_array = new string[x][y];
>
> auto some_array = new string[][](x, y);
>
> Note, this creates 10 arrays of 10 elements all on the heap, 
> and then a 10 element array to point at them.
>
> If you wanted an array of 10 *fixed sized* arrays (which is 
> what your code was trying to do), then you need to have the 
> first dimension be a compile-time constant such as a literal or 
> an enum/immutable.
>
> -Steve

Thanks!!!
This is what I need!
auto some_array = new string[][](x, y);


More information about the Digitalmars-d mailing list