variable x cannot be read at compile time - how to get around this?
ketmar via Digitalmars-d
digitalmars-d at puremagic.com
Wed Nov 12 23:54:46 PST 2014
On Thu, 13 Nov 2014 07:08:17 +0000
Sergey via Digitalmars-d <digitalmars-d at puremagic.com> 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];
> 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.
you can't. use static constructor.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20141113/a252336f/attachment.sig>
More information about the Digitalmars-d
mailing list