When I need to use something that needs to also be declared in the header, let’s say a member variable of some specific scene component, I’ve always included the header of the component in my header and that was it. It was then available in both my header and my .cpp for use. Recently, I’ve noticed that in the Unreal’s internal classes, it’s usually done such that there’s only forward declaration of the class in the header, and the actual inclusion of the header happens in C++.
For example, what I do
#include "Components/CapsuleComponent.h" UCapsuleComponent* Capsule;
What Epic does:
class UCapsuleComponent; UCapsuleComponent* Capsule;
#include "Components/CapsuleComponent.h" Capsule->InitCapsuleSize(50.0f, 100.0f);
I wonder what is the reason to do it this other way? Performance… or…?
Thanks in advance.