Pointer to incomplete class type is not allowed

I’m new to C++, and newer still to Unreal Engine 4. I’m following a video tutorial to simply rotate an object created with c++. The video appears to be somewhat out of date, being six months old. On one line I get an error with the line this->SampleMesh->AttachtoComponent(this->RootComponent); stating pointer to incomplete class type is not allowed. I’ve searched for ways around it, but have had no luck so far. If anyone knows the updated way to do this, I would be grateful. Thanks.

Pickup.cpp

#include "Pickup.h"

// Sets default values
APickup::APickup()
{
// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;

SampleMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("SampleMesh"));

this->SceneComponent = CreateDefaultSubobject<USceneComponent>(TEXT("SceneComponent"));

this->RootComponent = SceneComponent;

this->SampleMesh->AttachtoComponent(this->RootComponent);


this->RotationRate = FRotator(0.0f, 180.0f, 0.0f);

this->Speed = 1.0f;
}

// Called when the game starts or when spawned
void APickup::BeginPlay()
{
Super::BeginPlay();

}

// Called every frame
void APickup::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);

this->AddActorLocalRotation(this->RotationRate * DeltaTime * Speed);
}

Pickup.h

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Pickup.generated.h"

UCLASS()
class LEARNAGAIN_API APickup : public AActor
{
GENERATED_BODY()

public:	
// Sets default values for this actor's properties
APickup();

protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;

public:	
// Called every frame
virtual void Tick(float DeltaTime) override;

UPROPERTY(EditAnywhere, BluePrintReadWrite, Category = Pickup)
UStaticMeshComponent* SampleMesh;

UPROPERTY(EditAnywhere, BluePrintReadWrite, Category = Pickup)
FRotator RotationRate;

UPROPERTY(EditAnywhere, BluePrintReadWrite, Category = Pickup)
USceneComponent* SceneComponent;

UPROPERTY(EditAnywhere, BluePrintReadWrite, Category = Pickup)
float Speed;

};

Hey, first of all, I would get rid of using the keyword this, it’s just visual noise and you are fine if you left it out.

Second, if you initialize something in the constructor there is sometimes a special init function, next to a set function. In this case, you have to use SampleMesh->SetupAttachment(RootComponent); instead of SampleMesh->AttachtoComponent(RootComponent);

Third, Unreal changed to a IWYU model (make sure to read this), which means you have to include the SkeletalMeshComponent on top of your class like this #include "Classes/Components/SkeletalMeshComponent.h"

Just report back if you have any questions, I’m glad to help.