我在我的Cocos2d-Iphone应用程序中使用了几个NS_ENUM,我使用Apportable将其移植到Android。应用程序在Xcode中工作完美,但我得到几个错误与NS_ENUM的时候使用Apportable构建。下面是一些错误:
/Users/mac/Documents/BallTestApp/BallManager.mm:57:32: error: assigning to 'ballTypes' from incompatible type 'int'
lastCreatedBallType = NULL;
^ ~~~~
/Users/mac/Documents/BallTestApp/BallManager.mm:382:66: error: cannot initialize a parameter of type 'ballTypes' with an lvalue of type 'int'
withBallType:pBallType atLocation:ballPosition withManager:self];
^~~~~~~~~
/Users/mac/Documents/BallTestApp/Ball.h:193:103: note: passing argument to parameter 'myType' here
-(id)initBallWithWorld:(b2World*)world inLayer:(GamePlayLayer*)layer withBallType:(ballTypes)myType atLocation:(CGPoint)myLocation withManager:(BallManager*)myBallManager;
^
/Users/mac/Documents/BallTestApp/BallManager.mm:575:79: error: cannot initialize a parameter of type 'xBallDistances' with an lvalue of type 'int'
myBallPos = self.carlBall.position.x + [self getBallDistance:i];
^
我将ballTypes定义为:
typedef NS_ENUM(NSUInteger, ballTypes) {
redBall = 0,
yellowBall = 1,
blueBall = 2,
greenBall = 3
};
我也以类似的方式定义了其他枚举。
NULL的定义如下:
#define NULL 0
因此,您试图将int 0赋值给enum值。
用= redBall
代替= NULL
可以解决这个问题。