[英]Including two header files in c++
I have a project I'm working on and I'm currently working on the header files.我有一个正在处理的项目,我目前正在处理 header 文件。 For simplicity let's say I have two header files so far.
为简单起见,假设到目前为止我有两个 header 文件。 fileX.h and fileY.h
文件X.h 和文件Y.h
The code I have in both is just class definitions.我在两者中的代码只是 class 定义。 But, fileX needs fileY's class definitions and fileY needs fileX.
但是,fileX 需要 fileY 的 class 定义,而 fileY 需要 fileX。 I tried having inside of fileX a
#include "fileY.h"
and have a include "fileX.h"
inside of my fileY, but I'm getting an error that gets in a never ending loop.我尝试在 fileX 内部添加一个
#include "fileY.h"
并在我的 fileY 内部添加一个 include "fileX.h include "fileX.h"
,但是我遇到了一个错误,该错误进入了一个永无止境的循环。 How can I fix this?我怎样才能解决这个问题? Thanks
谢谢
How can I fix this?
我怎样才能解决这个问题?
By breaking the circular dependency.通过打破循环依赖。 Its simply impossible for A to depends on B's definition while also B depending on A's definition.
A根本不可能取决于B的定义,而B也取决于A的定义。 You must get rid of one of the dependencies.
您必须摆脱其中一种依赖关系。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.