Why do we include the 'using' statement for int32 in the cpp file, but not the one for FString?



I know the header is being hash-included in the FBCG.cpp file anyway, but we still include “using int32 = int;” anyway. So why wouldn’t we also include “using FString = std::string;”?

Obviously the code still works, but still curious. Is it just an inconsistency in practice? Should we include both statements, or neither?

screenshot of git changes to the .cpp from this lecture, circle emphases mine:


Yeah, it wasn’t really mentioned why we did that. Like you said its being pasted in anyways from the header file and if you comment out the using int32 = int; in the class it still works fine which shows that the header using is working. Maybe it was just to be extra explicit but in this case it does seem redundant and arbitrary because the same wasn’t done for FString. Maybe it matters in Unreal? Haven’t gotten that far yet myself. I’d be interested in the answer though.


I have the same question. we could have added “using int32 = int;” only in FBullCowGame.h and it would work for all the project. I tested and it works just fine. Maybe there is another reason behind this. As you said, perhaps is something that Unreal needs.


I haven’t really thought about it, but you shouldn’t need to have using int32 = int; in the cpp-file, since it’s already declared in the header file and that is hash-included in the cpp-file.

I have for now commented it out in both my cpp-files to avoid any confusions.


Hi there,

I think it boils down to safeguarding.
Because the compiler will require the using statement in order to interpret the references to int32 it is better to not risk it being missed out in any way - the key is to be explicit.
One might also argue that by not declaring it in the .cpp you are creating an unnecessary dependency but this exists anyway as it’s the .cpp of the .h file so the reason is likely more to do with safeguarding.