Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

error: invalid lvalue in assignment



Hello everyone!

I'm having a problem using a property for one of my custom class objects.

I have a class like this:


INTERFACE (MyObject.h): -----------------------------------

typedef struct {
	float x;
	float y;
} Vector2D;

@interface myObject : NSObject {
	Vector2D _position;
}

@property Vector2D position;

@end


IMPLEMENTATION (MyObject.m): ---------------------------------------------

@implementation myObject

@synthesize position=_position;

- (id)init
{
	if ((self=[super init]) != nil) {
		_position.x = 0.0;
		_position.y = 0.0;
	}
	return self;
}

@end

I tried to modify the "position" property in another file after creating an object but I get this error:

	obj.position.x += 1.0;
	(x error: invalid lvalue in assignment)

I can assign the value without a problem:

		float x = obj.position.x;
		x += 1.0;

But then this is also a no-no:

		obj.position.x = x;

Anyone have any ideas as to why the first assignment gives an error?

Thanks for any and all help.
- Don


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.