What does "class" in class UPointLightComponent* PointLight1; mean?

I am reviewing C++ for Unreal Engine, and I came across the Class Creation Basics Code Only page. What I do not understand is this statement in the LightSwitchCodeOnly.h file:

class UPointLightComponent* PointLight1;

And similarly, the class AActor* OtherActor and class UPrimitiveComponent* OtherComp parementers in the OnOverlapBegin function in the same header:

UFUNCTION()
void OnOverlapBegin(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);

If it’s AActor* OtherActor or UPrimitiveComponent* OtherComp, it means these are pointers to AActor and UPrimitiveComponent objects, is that correct (please correct me if I’m wrong!)? Why is there a class here? What does that mean?

This is a forward declaration for the type. This allows you to use a pointer to the type without having to include the relevant header file in your header file (instead you only need it in the .cpp file).

This helps to reduce dependencies which can improve compile time.

It isn’t always needed, particularly with Unreal core classes as these are often included anyway. However it is good practise to use the prefix if you haven’t explicitly included the header file. If you do this, if whatever file was including the header changes to not include it, your code will still compile.

Thanks for the answer. Just to if I understand correctly, do they mean " OtherActor is a pointer to an AActor object", " OtherComp is a pointer to a UPrimitiveComponent object", the class is there only so that a header file does not have to be included?

That’s right, it is included then in the .cpp

Actually, it is an ‘elaborated type specifier’. Forward declarations are a subset of elaborated type specifiers, and while forward declarations are good (for the reasons says), you should avoid ETSs.

If you want to forward declare your types, it is best to do so explicitly at file scope:

class Bad
{
    void Func(class Y* YParam);
    class Z* ZProp;
};


class Y;
class Z;
class Good
{
    void Func(Y* YParam);
    Z* ZProp;
};

Steve