Missing forward declaration of UTankTurret

I noticed in this video at around 4:48, we are forward declaring UTankBarrel, but not UTankTurret in Tank.h… but the code still compiles. I spent a while trying to work out as to why this is, and I thought I’d share in case anyone else spotted this and wondered what was going on!

It turns out that setting SetTurretReference() to being BlueprintCallable results in the Tank.generated.h file automatically generating forward declarations for any classes that it needs for this function (in this case UTankTurret). As Tank.generated.h is #included in Tank.h, this forward declaration propogates through to Tank.h and allows the program to successfully compile.

This is also true of the UTankBarrel; removing this class’s forward declaration also results in successful compilation.

However, I think that these classes should still be forward declared in Tank.h, because if we decide later down the line that we don’t want to call SetBarrelReference() or SetTurretReference() from the Blueprint, removing the BlueprintCallable property without explicity forward declaring UTankBarrel and UTankTurret could result in a potentially confusing compilation error!

1 Like

Privacy & Terms