我正在努力学习目标c。
这都在我的.m文件中
@interface TetrisEngine ()
@property (nonatomic, readwrite) struct TetrisPiece *currPiece;
@end
struct TetrisPiece {
int name;
struct {
int colOff, rowOff;
} offsets[TetrisPieceRotations][TetrisPieceBlocks];
};
下一个人的内容不应该相关。我假设您需要查看返回值才能提供帮助
static struct TetrisPiece pieces[TetrisNumPieces] = {...};
@implementation TetrisEngine
@synthesize currPiece;
- (void) nextPiece
currPiece = &pieces[ ((random() % (TetrisNumPieces * 113)) + 3) % TetrisNumPieces];
这就是我得到错误的地方:从'struct TetrisPiece *'中分配给'struct TetrisPiece *'的指针类型不兼容
答案 0 :(得分:4)
需要为c-type指针显式声明文件var,如...
@interface TetrisEngine () {
// added curly braces and this
struct TetrisPiece *currPiece;
}
@property (nonatomic, readwrite) struct TetrisPiece *currPiece;
@end
其余的应该按原样运作。虽然我同意另一个答案,即有更多现代方法在oo中声明结构。