[英]Objective C++ lvalue required as unary '&' operand
我正在使用SDL2開發游戲引擎,我的方法有錯誤“需要左值作為一元'&'操作數”
// Class Enviroment
@interface Environment : NSObject
{
SDL_Rect groundPos;
}
// Class Game
@interface Game: NSObject
{
-(SDL_Surface *) addItem: (const char *) file andRegion: (SDL_Rect *) region
{
SDL_Surface * temp;
SDL_Surface * formatted;
temp = IMG_Load(file);
formatted = SDL_ConvertSurface(temp, temp->format, NULL);
temp = NULL;
return formatted;
}
-(void) loadSurfaces
{
SDL_Surface *ground;
ground = [self addItem: "media/ground.bmp" andRegion: &environment.groundPos];
}
}
我正在使用Windows和編譯器gcc上的代碼塊創建器在Objective-C ++中對其進行編碼
不知道environment
我無法回答...但是我猜測您可能可以做幾件不同的事情之一(取決於實際的類型):
//(POD just passing in a copy of the value by ptr)
SDL_Rect region = environment.groundPos
ground = [self addItem: "media/ground.bmp" andRegion: ®ion];
//(Environment is a ptr and has a SDL_RECT ptr member)
ground = [self addItem: "media/ground.bmp" andRegion: environment->groundPos];
//(Member is a POD)
ground = [self addItem: "media/ground.bmp" andRegion: &(environment->groundPos)];
//(maybe what you are trying dereference and dot operator, parens to make explicit)
ground = [self addItem: "media/ground.bmp" andRegion: (*environment).groundPos]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.