不兼容的指针类型从“结构MYSTRUCT *”
问题描述:
分配给“结构MYSTRUCT *”我想学习目标C。不兼容的指针类型从“结构MYSTRUCT *”
这是在我的.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];
,这是我得到的错误:不兼容的指针类型从“结构TetrisPiece *”
分配给“结构TetrisPiece *”
答
文件VAR需要为C型指针,像这样明确声明...
@interface TetrisEngine() {
// added curly braces and this
struct TetrisPiece *currPiece;
}
@property (nonatomic, readwrite) struct TetrisPiece *currPiece;
@end
其余的将正常运行是。虽然我同意另一个答案,即有更多现代方法来声明oo中的结构。
如果你有一个语言OO设施,为什么使用结构在这里? – 2012-05-06 04:36:13