Include in header or cpp

I am confused about the challenge in the Unreal C++ course lecture 220. The C++ Compilation Process. When I try moving the #include “Tank.h” out of TankPlayerController.h and put it in TankPlayerController.cpp (before TankPlayerController.h) I get the following compile errors:

1>C:\Users\Scott\Documents\Unreal Projects\BattleTank\Source\BattleTank/Public/TankPlayerController.h(32): error C2143: syntax error: missing ‘;’ before ‘*’
1>C:\Users\Scott\Documents\Unreal Projects\BattleTank\Source\BattleTank/Public/TankPlayerController.h(32): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Users\Scott\Documents\Unreal Projects\BattleTank\Source\BattleTank/Public/TankPlayerController.h(32): error C2238: unexpected token(s) preceding ‘;’

I am using Unreal Editor 4.24, which I see a note at 5:27 that “4.17+ now requires the header to be the first include so we cannot do this reordering anymore.” Does that mean I have to keep the Tank.h in the TankPlayerController.h, which Ben said we shouldn’t be doing in the video? I want to make sure I’m following best practices.

Update: It looks like forward declarations will solve this particular problem. Is that what I should be using instead?

Using forward declarations is always preferred when you can.

Privacy & Terms