Strange multiple compiler errors while including a header file

Hi guys,
I’m having a strange behaviour while including the following header file highlited in the red box:

I’m following the ToonTanks section of the course and I’m currently on video 158 (Spawning Particles).

Here are all the errors I get whe I include this file:

The weird this is that if I do not include that file, everything compiles just fine and the project works.

Also, if I move the include delaration to the cpp file, that also seems to work fine.

To me, ths seems to be an issue with imports, maybe multiple imports defined or something like that?

Would you have any idea as to why this is happening?

The only thing I can think of is that, throught the project, I always included all the required headers file in the .h files, and not in the .cpp files. Would this be an issue?

Thank you in advance :slight_smile:

That would indicate a problem with the header file you are including. #include is just a copy and paste.

Thank you Dan for your quick reply.

Just for clarification, here is the header file I’m importing:

I can’t see any issue with the code written in the header file.
Also this class is actually used inside the project and compiles fine if not included in the “pawnBase.h” file.

Am I missing something?

What about TankGameMode.h?

Here it is:

Then that would be why. You have a circular dependency with that and this is why you should always use forward declarations when you can.

PawnBase.h includes HealthComponent.h which includes TankGameMode.h which includes PawnBase.h which includes HealthComponent.h which includes TankGameMode.h …

oh I see!

I thought #pragma once is taking care of not including the header file multiple times?

so it is always the case that you forward declare your classes in the header files and only include other headers in the cpp files?

That’s kind of the issue here. Judging by the error message HealthComponent isn’t getting the declaration of the game mode

You should only include what the header file needs and forward declare what you can. For example I see that you’re including GamePlayStatics in a header file when it doesn’t use it at all.

Thank you very much Dan,
I will refactor the whole project following these guidelines.

Thanks a lot for your fast reply :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms