-
structure syntax error
this is the relevant section of a piece of code I am having trouble with.
Code:
struct waypointDef;
struct waypointDef waypoints[];
waypointDef.waypoints[] = { { (-800000000 - longin1) , (370000000 + latin1), 75 } , F_ABSOLUTE };
The compiler returns with a syntax error before the '.' in waypointDef.waypoints[]. I have tried the same code without that line and it compiles fine. Can someone find my error?
-
Code:
struct waypointDef;
struct waypointDef waypoints[] = { { (-800000000 - longin1) , (370000000 + latin1), 75 } , F_ABSOLUTE };
You must initialize on the declaration. Otherwise you can only assign.
struct waypointDef; <--- Is this a forward declaration?
struct waypointDef waypoints[]; <--- Must specify size.
waypointDef.waypoints[] <--- Does waypointDef have a member waypoints, and is that what you're trying to initialize?
-
i've also tried
Code:
struct waypointDef waypoints[] = { { (-800000000) , (370000000), 75 } , F_ABSOLUTE };
waypointDef.waypoints[] = { { (-800000000 - longin1) , (370000000 + latin1), 75 } , F_ABSOLUTE };
but got the same error.
and yes, i am trying to initialize the member waypoints and then change its value
do I have to specify size though? this same code works fine if I just remove the waypointDef.waypoints line
thanks
-
You cannot reassign in the way you're attempting in your second line.
In your first line, the compiler is able to infer the size from the data you are using to initialise the array. That can only be done upon initialisation, not upon assignment after initialisation (which are the cases where your compiler is complaining).
-
Can i see the structure members?
-
-
How do you change values in a structure after initialization?
-
By assigning to them individually :)
-
so do i have to abandon the structures entirely?
or is there a less painful way to fix my code?
-
Either initialize the entire structure in one fell swoop, or assign them separately. Those are your two options.
-
Yeah, you are not abandoning the use of structures. You are just assigning to the individual members of a structure. If you find it more convenience, write a function to help you do it.