Thread overview | |||||
---|---|---|---|---|---|
|
December 26, 2015 Creation of an array which length depens on variables not possible? | ||||
---|---|---|---|---|
| ||||
Why is this not possible? GtkAllocation size; widget.getAllocation(size); this.width = size.width; this.height = size.height; int[size.width*size.height*3+1] arr; this.accumulator = arr; nor this: GtkAllocation size; widget.getAllocation(size); this.width = size.width; this.height = size.height; int[this.width*this.height*3+1] arr; this.accumulator = arr; in the constructor? |
December 26, 2015 Re: Creation of an array which length depens on variables not possible? | ||||
---|---|---|---|---|
| ||||
Posted in reply to TheDGuy | 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. |
December 26, 2015 Re: Creation of an array which length depens on variables not possible? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | On Saturday, 26 December 2015 at 18:49:26 UTC, Adam D. Ruppe wrote:
> 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.
Thank you very much, it really helped me a lot!
|
Copyright © 1999-2021 by the D Language Foundation