다음은 2 개의 구조체에 대한 정의입니다. 다음은이 구조체를 사용하는 짧은 메서드 본문입니다. 컴파일러는 오류가 발생하는 이유 이해가 안 :이 구조체의 포인터에 올바르게 액세스하려면 어떻게해야합니까?
physics.c:95: error: incompatible types in assignment
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
}
[objectIndex] = body; – nope