Forward declare a class

I have two classes. ABalloon and ABalloonGenerator. The generator drops balloons so it needs “Public/Balloon.h” and the balloon needs to get some information from the generator so it needs “Public/BalloonGenerator.h” but you cannot have the headers including each other or you get recursion.

How do I forward declare a pointer to the class so that I can get all the publics (vars, functions, etc.) from each class in the other class??

Let me know if this is not clear enough.

Forward declaration does not include any knowledge about publics (vars, functions, etc.), the only thing it does is to tell the compiler that you have a class/struct/enum of that type defined somewhere else.

And just from a design perspective Balloon should not need BalloonGenerator.

Suggestion on how to solve your problem:

  • Forward declare Balloon in BalloonGenerator

     your includes
     class ABalloon;
     your ABalloonGenerator
  • And in your spawn function in the generator set all the information the Balloon needs from the generator

     #include "Balloon.h" // include balloon in the cpp
     in the spawn function:
     auto* Balloon = GetWorld()->SpawnActor<ABalloon>(BalloonClassToSpawn, CreatePosition, Rotation, SpawnInfo);
     Balloon->Setup(all the information it needs to get)

That means only the BalloonGenerator.cpp needs to include the Balloon and you have no dependency from Balloon to the BalloonGenerator

Thanks, this is a good solution. I just got caught up in a tangent and wasn’t thinking what I was doing. Thanks for putting me back on track!