Initializing Arrays

Lionello Lunesu lionello at lunesu.remove.com
Sun Jan 21 12:31:15 PST 2007


Not sure if it'll work, but try using [cast(celcius)0,20,18].
Casting the first element will change the type of the array.

L.

"Joseph Bell" <josephabell at tx.rr.com> wrote in message 
news:ep0h1h$18ph$1 at digitaldaemon.com...
> Hi.
>
> I'm new to D but not new to programming.  I had a few questions regarding 
> arrays and their initialization:
>
> // celsius.init will be 100, the boiling point of water
> typedef float celsius = 100.00;
>
> If I declare an array of type celsius to group the low, average, and high 
> temperature:
>
> celsius[3] temps;
>
> I'd like to be able to default the elements to something other than the 
> value of celsius.init:  a syntax like
>
> celsius[3] temps = [0, 20, 18];
>
> In the global namespace (outside of main) the gdc compiler doesn't have 
> any issues with this and gives me what I expect, temps[0] = 0.0, temps[1] 
> = 20.0, and temps[2] = 18.0.  Within main however I get errors such as:
>
> arrayex.d:22: Error: cannot implicitly convert expression ([0,20,18]) of 
> type int[3] to celsius.
>
> Is there a way to uniquely specify the default value of each element of an 
> array in this manner in a non-global namespace?
>
> Many thanks for any insight.
>
> Joe 





More information about the Digitalmars-d mailing list