简体   繁体   中英

Including two header files in c++

I have a project I'm working on and I'm currently working on the header files. For simplicity let's say I have two header files so far. fileX.h and fileY.h

The code I have in both is just class definitions. But, fileX needs fileY's class definitions and fileY needs 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. 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. You must get rid of one of the dependencies.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM