我有两个结构需要互相引用,无论我先抛出哪一个抛出错误,因为我使用的是一个未识别的类型。
typedef struct _BLOCK
{
int size;
int offset;
struct _BLOCK *nextBlock;
struct _BLOCK *prevBlock;
Pool* parent; //here
} Block;
typedef struct _POOL
{
int size;
void* memory;
Block* Allocated;
Block* Unallocated;
} Pool;
有任何解决方法吗?
答案 0 :(得分:4)
您可以使用前向声明。
typedef struct _POOL Pool;
typedef struct _BLOCK
{
int size;
int offset;
struct _BLOCK *nextBlock;
struct _BLOCK *prevBlock;
Pool* parent;
} Block;
struct _POOL
{
int size;
void* memory;
Block* Allocated;
Block* Unallocated;
};