Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Is "class Name*" a class pointer?

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;
like image 514
Chrismar Avatar asked Aug 15 '26 15:08

Chrismar


1 Answers

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.

like image 153
bolov Avatar answered Aug 19 '26 11:08

bolov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!