Domanda

I'm trying to learn objective c.

this is all in my .m file

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

struct TetrisPiece {
    int name;
    struct {
        int colOff, rowOff;
    } offsets[TetrisPieceRotations][TetrisPieceBlocks];
};

the contents of this next guy should not be relevant. i assume the return value is all you need to see in order to help out

static struct TetrisPiece pieces[TetrisNumPieces] = {...};

@implementation TetrisEngine
@synthesize currPiece;

- (void) nextPiece
    currPiece = &pieces[ ((random() % (TetrisNumPieces * 113)) + 3) % TetrisNumPieces];

and this is where i get the error: Incompatible pointer types assigning to 'struct TetrisPiece *' from 'struct TetrisPiece *'

È stato utile?

Soluzione

The file var needs to be declared explicitly for the c-type pointer, like this...

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

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

The rest should work as is. Though I agree with the other answer that there are more modern ways to declare structs in oo.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top