目标C ++左值作为一元'&'操作数

时间:2014-11-26 14:29:53

标签: c++ objective-c objective-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上的codeblocks creator和编译器gcc在objective-c ++中对其进行编码

1 个答案:

答案 0 :(得分:0)

不知道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]