作为一元'&'操作数所需的目标C++值



我正在使用 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: &region];
//(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]

相关内容

最新更新