我正在使用 Visual Studio 2010 开发一个 C++ 程序。我有这些类定义和头文件:
sh:
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.hbefore oe.h,并且我们引用了类's' o.h,所以我们必须包含s.hbefore o.h,但我们不能这样做,因为s.h需要oe.h&oe.h需要o.h&o.h需要s.h!
如您所见,类依赖循环中存在某种循环,因此我无法编译该项目。如果我删除 sh & th & oe.h 之间的依赖关系,问题就会解决(这里是stdafx.h针对这种状态的):
#include "s.h"
#include "t.h"
#include "o.h"
#include "oe.h"
但我必须使用所有给定的依赖项并且我不能删除任何依赖项。任何的想法?