下面是 2 个结构的定义,然后是使用它们的简短方法体。我不明白为什么编译器会抛出错误:
physics.c:95:错误:分配中的类型不兼容
cpBody
并且cpSpace
是来自外部库的类型,这不是问题的一部分。
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
};
void physicsAddBody(gameSpace *space, gameBody *body, int objectIndex)
{
gameBody *array = space -> arrayOfObjects;
array[objectIndex] = body; //THIS IS WHERE THE ERROR IS THROWN
}