Home > Mobile >  Including two header files in c
Including two header files in c

Time:01-15

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

CodePudding user response:

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.

  •  Tags:  
  • Related