我正在實現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