开发者

Objective-c access struct variable from an array of structs

开发者 https://www.devze.com 2023-01-21 11:55 出处:网络
I have a struct called Point typedef struct { GLfloat x; GLfloat y; } Point; create an array of Points: Point *sPoints;

I have a struct called Point

typedef struct {
GLfloat x;
GLfloat y;
} Point;

create an array of Points:

Point *sPoints;
for(int i=0 ... // define sPoints

somewhere else, I want to alter variables on those points. Why does this work:

sPoints[100].x+=10;    

but this doesn't:

Point pt = sPoints[100];
pt.x +=10;

is there any way to create a temporary variable that refers to the Point structure and allows me to set properties of that struct? The really strange thing is that in my non working code (pt.x +=10) I can actually read pt.x fine, I ju开发者_开发技巧st can't seem to assign it... any help appreciated.


It doesn't work because in C, that operation:

Point pt = sPoints[100];

creates a copy of the item on the right hand side, whereas the former does not copy.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号