相互引用的结构 [英] 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?
推荐答案
可以使用前置声明.
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;
};
这篇关于相互引用的结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文