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

Sergey via Digitalmars-d digitalmars-d at puremagic.com
Wed Nov 12 23:08:17 PST 2014


   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];
variable x cannot be read at compile time

I tried this:
enum columns_array = 
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20];
auto y = 10;
int i = 1;
auto some_array = new string[columns_array[i]][y];
Error: columns_array is used as a type

And yet, if I have a function:
string[x][] some_function (some par) {
    auto x = 10;
    auto y = 10;
    auto some_array = new string[x][y];
    return some_array;
    }

Thanks in advance.


More information about the Digitalmars-d mailing list