我正在实现Box2d(用C++编写)的目标C封装器。 b2Body在其userData字段中保留对其包装器的引用。 GetUserData返回一个void *。我现在正在实施快速迭代,以便将B2B实体从B2World中提取出来。'从不兼容类型'分配'id'
我在下面指示的行中得到'来自不兼容类型'B2Body *'错误的'分配给'id'。为什么?
#import "B2Body.h"
#import "B2World.h"
#import "Box2d.h"
@implementation B2World
-(id) initWithGravity:(struct B2Vec2) g
{
if (self = [super init])
{
b2Vec2 *gPrim = (b2Vec2*)&g;
_world = new b2World(*gPrim);
}
return self;
}
- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id __unsafe_unretained [])buffer count:(NSUInteger)len;
{
if(state->state == 0)
{
state->mutationsPtr = (unsigned long *)self;
state->extra[0] = (long) ((b2World*)_world)->GetBodyList();
state->state = 1;
}
// pull the box2d body out of extra[0]
b2Body *b = (b2Body*)state->extra[0];
// if it's nil then we're done enumerating, return 0 to end
if(b == nil)
{
return nil;
}
// otherwise, point itemsPtr at the node's value
state->itemsPtr = ((B2Body*)b->GetUserData()); // ERROR
state->extra[0] = (long)b->GetNext();
// we're returning exactly one item
return 1;
}
`
B2Body.h看起来像这样: #进口
@interface B2Body : NSObject
{
int f;
}
-(id) init;
@end
下面哪条线表示? – deanWombourne
标有// ERROR –
的那个啊,对不起。我是盲人:) – deanWombourne