开发者

'struct objc_object' has no member named 'position'

So I have this class called a Cell which is a subclass of CCSprite then I have three other subclasses of Cell.

In one of the subclasses I am overriding a method called addCellToCell in cl开发者_运维技巧ass Cell:

-(void)addCellToCell:(id)_cell;

And I am trying to do this:

    self = [CCSprite spriteWithFile:@"Jet.png"];
    [self setPosition:ccp(_cell.position.x+5, _cell.position.y)];

Where I am trying to set the object self's position (which since it is inheriting from Cell it makes it essentially a modified CCSprite) relative to another Cell subclassed object (potentially from any one of the three subclasses).

But when I do this I get the error:

request for member 'position' in '_cell', which is of non-class type 'objc_object*'

It also suggest I use "->" instead of "." so I change it to that:

'struct objc_object' has no member named 'position'

Sorry if it is confusing... Please ask for any clarification if you need some. How can I fix these errors?

Definition of Cell class:

@interface Cell : CCSprite {
}

-(void)addToCell:(id)_cell;

@end


Cast it to Cell object before using it,

Cell aCell = (Cell *)_cell;

and then

[self setPosition:ccp(aCell.position.x+5, aCell.position.y)];


Just change

-(void)addCellToCell:(id)_cell;

to

-(void)addCellToCell:(Cell*)_cell;

Don't use id unless absolutely necessary. Always use ClassName* instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜