如何防止头文件嵌套问题
最近由于项目的头文件不断增多,以及头文件之间不断的相互引用导致头文件嵌套......
无法找到问题的根本原因,
请问有过相关经验的朋友如何解决这类问题的........
头文件数量 200+
谢谢 回复 1# Buddy_Zhang1
我自己遇到这种情况,会用下面这两种方法:
① 把类型提前声明一下
file-a.h:
#include "file-b.h"
struct B;
struct A {
struct B *b;
};
file-b.h:
#include "file-a.h"
struct A;
struct B {
struct A *a;
};
② 把struct A、struct B定义在comm.h,然后:
file-a.h:
#include "comm.h"
file-b.h:
#include "comm.h" 回复 2# _nosay
我的头文件都是使用这种写法的,
页:
[1]