C++ 目标C和x2B+;左值要求为一元'&';操作数
我正在使用SDL2开发一个游戏引擎。我的方法有错误“一元需要左值”和“操作数”C++ 目标C和x2B+;左值要求为一元'&';操作数,c++,objective-c,objective-c++,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
// 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];
}
}
我正在用objective-c++在windows上使用codeblocks creator和编译器gcc对其进行编码而不知道
环境
我无法回答。。。但是我猜你可能会做一些不同的事情(取决于实际的类型):
您是否有包括行号在内的完整错误?什么是
environment.groundPos
?它是如何定义的?只是一个猜测:environment
和类environment
的实例,是否有@property
声明groundPos
?在这种情况下,environment.groundPos
实际上并不是它看起来的样子:Objective-C被分解成调用[environment groundPos]
,它将表达式呈现为和[environment groundPos]
//(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]