[英]Structs that reference each other
I have two structs that need to reference each other, however whichever one I put first throws and error because I am using an unidentified type. 我有两个需要互相引用的结构,但是无论我首先提出哪个结构,都会出错,因为我使用的是不明类型。
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;
any ways to resolve this? 有什么办法解决这个问题?
You can use forward declaration. 您可以使用前向声明。
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;
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.