引发错误,我不确定原因:
physics.c:74:错误:初始化中不兼容的类型
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];
}
答案 0 :(得分:1)
我猜它在行
gameBody *gBody = space -> arrayOfObjects[i];
虽然space->arrayOfObject
是指针,但space->arrayOfObject[i]
不是指针。
您必须声明gBody
不是指针:
gameBody gBody = space->arrayOfObjects[i];
或者在数组中的对象上使用address-of运算符;
gameBody *gBody = &space->arrayOfObjects[i];
答案 1 :(得分:1)
试
gameBody *gBody = &(space -> arrayOfObjects[i]);
或
gameBody *gBody = space -> arrayOfObjects + i;
答案 2 :(得分:0)
gBody
的类型为gameBody *
,space->arrayOfObjects[i]
的类型为gamebody
。也许你想要:
gameBody *gBody = &space->arrayOfObjects[i];
答案 3 :(得分:0)
来自您发布的代码
gameBody *gBody = space->arrayOfObjects[i]
&lt;〜是问题......
应该是:
gameBody *gBody = &(space->arrayOfObjects[i]);