我正在开发使用Visual Studio 2010中C++程序我有这些类定义&头文件:
SH:循环类的依赖,而包括C头文件++
class s : oe {
...
};
日:
class t : oe {
...
};
oe.h:
class oe {
...
o getO();//we reference to class 'o' in oe.h, so we must include o.h begore oe.h
};
&哦:
class o {
...
s getS();//we reference to class 's' in o.h, so we must include s.h begore o.h
};
的问题是,我们参照“O”级在oe.h
,所以我们必须包括o.h
oe.h
之前,&我们也参考o.h
类的',所以我们必须包括s.h
o.h
之前,但我们不能这样做,因为s.h
需要oe.h
& oe.h
需求o.h
& o.h
需求s.h
!
正如你所看到的,在类依赖周期&中存在某种循环,所以我无法编译该项目。如果我SH &之间移除日& oe.h的依赖性,这个问题就会解决(这里是stdafx.h
这个状态):
#include "s.h"
#include "t.h"
#include "o.h"
#include "oe.h"
,但我必须使用所有给定的依赖&我不能删除依赖任何人。任何想法?
[头文件之间的循环依赖关系]可能的重复(http://stackoverflow.com/questions/2089056/cyclic-dependency-between-header-files) – RedX
搜索forwad声明和循环头依赖。关于stackoverflow有很多问题。 – RedX