我需要财产的访问地址,但有问题。示例代码是
@interface Rectangle : NSObject
{
SDL_Rect wall;
SDL_Rect ground;
}
@property SDL_Rect wall;
@property SDL_Rect ground;
@end
@implementation Rectangle
@synthesize x;
@synthesize y;
@end
@interface Graphics : NSObject
{
int w;
int h;
}
-(void) drawSurface
@end
@implementation Graphics
-(void) drawSurface
{
Rectangle *rect = [[Rectangle alloc] init];
SDL_BlitSurface(camera, NULL, background, &rect.wall);
}
@end
&rect.x 是请求的属性表达式的地址
正如评论所暗示的,您不能获取财产的地址。属性实际上只是一个承诺,即相关对象为某些值提供访问器。该值本身可能存在于实例变量中,也可能不存在。例如,名为的属性的 getterfullName
可能会通过连接值来动态生成所需的值firstName
and lastName
特性。
由于您需要传递一个地址SDL_Rect
into SDL_BlitSurface()
,您可以首先将必要的属性复制到局部变量中,然后传递该变量的地址:
Rectangle *rect = [[Rectangle alloc] init];
SDL_Rect wall = rect.wall;
SDL_BlitSurface(camera, NULL, background, &wall);
如果您需要保留剩下的值wall
致电后SDL_BlitSurface()
,调用后再次复制回来:
rect.wall = wall;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)