how to initialize an array of struct
westcity
westcity1973 at hotmail.com
Thu Feb 12 03:34:10 PST 2009
Frits van Bommel дµ½:
> 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)
Thanks.
More information about the Digitalmars-d-learn
mailing list