how to initialize an array of struct

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Thu Feb 12 02:18:44 PST 2009


westcity wrote:
> My code is as following:
> 
> struct Point {
>         float x, y, z ;
> };
> 
> int main ()
> {
>         Point[3] pts = [
>                 {1.0, 0.0, 0.0} ,
>                 {0.0, 1.0, 0.0} ,
>                 {0.0, 0.0, 1.0}
>         ];
> 
>         return 0 ;
> }
> 
> But, the compiler report "Error: array initializers as expressions are not allowed".

That message's pretty messed up: array initializers look like [1.0, 0.0, 
0.0] in D.

> Then, how do I initialize an array of struct ? 

Replacing the middle lines with these works:
                 Point(1.0, 0.0, 0.0) ,
                 Point(0.0, 1.0, 0.0) ,
                 Point(0.0, 0.0, 1.0)


More information about the Digitalmars-d-learn mailing list