I was watching an unreal tutorial and encountered this line of code:
class UStaticMeshComponent* Pickup;
It is a forwards declaration. I have been studying c++ for a while and have not encountered anything like this before. I know about pointers and references, but I never seen this format: class Name*. Are we creating a class pointer to another class? I tried searching for class names followed by a *, but the only result that appeared were about data types and pointers.
public:
APickUp ();
virtual void BeginPlay () override;
virtual void tick ( float DeltaSeconds );
private:
class UStaticMeshComponent* Pickup;
class UStaticMeshComponent* Pickup;
This declares the type class UStaticMeshComponent
and also declares the variable Pickup
of type pointer to UStaticMeshComponent
. So the above code is more or less equivalent with:
class UStaticMeshComponent;
UStaticMeshComponent* Pickup;
Because at this point you don't have the definition of UStaticMeshComponent
(just the declaration), UStaticMeshComponent
is considered an incomplete type. There are a few things you can do with an incomplete type. One of them is declare pointers to them.