views:

15

answers:

2

When I try to compile my code where ann is an annotation, coordinate is a 2d coordinate, and latit is a float

ann.coordinate.latitude = latit;

I get an error message saying Ivalue required as left operand of assignment. What does this error mean and why is it showing up?

+1  A: 

The error is showing up because you're being confused by the two distinct uses of dot notation. The first is ann.coordinate, where coordinate is a property of whatever object ann is. The second is coordinate.latitude, where coordinate is a struct and latitude is a field in the struct. Normally one can assign to a property, as in ann.coordinate = aNewCoordinate. And normally one can assign to a struct field, as in coordinate.latitude = latit. However, one cannot assign to a field of an anonymous struct returned from a property getter. This will become quite obvious if you remove the property dot notation, as you are then left with [ann coordinate].latitude = latit, which is clearly wrong. Semantically, you are asking the compiler to construct code that looks similar to

__typeof__(ann.coordinate) __tempCoordinate = ann.coordinate;
__tempCoordinate.latitude = latit;
ann.coordinate = __tempCoordinate;

but this is far out of the scope of the dot syntax and the compiler refuses to generate this code (and rightfully so).

Kevin Ballard
+1  A: 

It means that when you do ann.coordinate.latitude you are actually trying to assign something to a getter. latitude RETURNS a value and you cannot assign something to it. You have to create a new coordinate and assign it to ann.

willcodejavaforfood