Creation of an array which length depens on variables not possible?

Adam D. Ruppe via Digitalmars-d digitalmars-d at puremagic.com
Sat Dec 26 10:49:26 PST 2015


On Saturday, 26 December 2015 at 18:43:51 UTC, TheDGuy wrote:
> Why is this not possible?
>
> 		int[size.width*size.height*3+1] arr;

Try:

auto arr = new int[](size.width*size.height*3+1);


The int[x] syntax declares a statically sized array - statically 
sized meaning it must be known at compile time and thus cannot be 
variables, along a few other differences.

The new array syntax though returns one of variable size.


More information about the Digitalmars-d mailing list