0

我正在努力学习目标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];

这就是我得到错误的地方: Incompatible pointer types assignmenting to 'struct TetrisPiece *' from 'struct TetrisPiece *'

4

1 回答 1

4

需要为 c 类型指针显式声明文件 var,如下所示...

@interface TetrisEngine () {
    // added curly braces and this
    struct TetrisPiece *currPiece;
}

@property (nonatomic, readwrite) struct TetrisPiece *currPiece;
@end

其余的应该按原样工作。尽管我同意另一个答案,即在 oo 中有更现代的方法来声明结构。

于 2012-05-06T04:59:25.363 回答