-2

An error is thrown, and I'm not sure sure why:

physics.c:74: error: incompatible types in initialization

typedef struct gameBody gameBody;

struct gameBody
{
    cpBody *body;
    int numberOfShapes;
    cpShape *arrayOfShapes; //This stores an array of pointers to Shapes
};

//Struct that stores the cpSpace object and the array of pointers to the body objects
typedef struct gameSpace gameSpace;

struct gameSpace
{ 
    cpSpace *space;
    int numberOfObjects;
    gameBody *arrayOfObjects;       //This stores an array of gameBodys
};


for(int i = 0; i < space -> numberOfObjects; i++)
{
    //body info
    gameBody *gBody = space -> arrayOfObjects[i];
}
4

4 回答 4

1

I'm guessing it's in the line

gameBody *gBody = space -> arrayOfObjects[i];

While space->arrayOfObject is a pointer, space->arrayOfObject[i] is not a pointer.

You either have to declare gBody to not be a pointer:

gameBody gBody = space->arrayOfObjects[i];

Or use the address-of operator on the object in the array;

gameBody *gBody = &space->arrayOfObjects[i];
于 2013-02-17T08:57:04.067 回答
1

try

 gameBody *gBody = &(space -> arrayOfObjects[i]);

or

gameBody *gBody = space -> arrayOfObjects + i;
于 2013-02-17T08:57:28.323 回答
0

gBody是 类型gameBody *space->arrayOfObjects[i]是 类型gamebody。也许你想要:

gameBody *gBody = &space->arrayOfObjects[i];
于 2013-02-17T08:58:05.870 回答
0

根据您发布的代码

gameBody *gBody = space->arrayOfObjects[i]<~问题来了...

应该是:

gameBody *gBody = &(space->arrayOfObjects[i]);

于 2013-02-17T08:58:09.047 回答