【发布时间】:2010-09-13 21:12:39
【问题描述】:
我有几个头文件,归结为:
树.h:
#include "element.h"
typedef struct tree_
{
struct *tree_ first_child;
struct *tree_ next_sibling;
int tag;
element *obj;
....
} tree;
和元素.h:
#include "tree.h"
typedef struct element_
{
tree *tree_parent;
char *name;
...
} element;
问题是它们都相互引用,所以tree需要包含元素,元素需要包含tree。
这不起作用,因为要定义“树”结构,元素结构必须已知,但要定义元素结构,树结构必须已知。
如何解决这些类型的循环(我认为这可能与“前向声明”有关?)?
【问题讨论】:
标签: c include-guards