Pointer to incomplete class type is not allowed

Hey there.I have been following the BatteryCollector tutorials from the LEARN tab of the UE’S website but I’ve come across a problem.On part 5 in BatteryPickup.cpp (look below) :
// Fill out your copyright notice in the Description page of Project Settings.

#include "BatteryCollector.h"
#include "BatteryCollector\Pickup.h"
#include "BatteryPickup.h"


// set default values
ABatteryPickup::ABatteryPickup()
{
	GetMesh()->SetSimulatePhysics(true); // when the batteries spawn in, they will fall from the sky
}

the GetMesh line throws this error : pointer to incomplete class type is not allowed.I tried solving it but nothing.And here is the Pickup.h script that contains the GetMesh function :

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

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

UCLASS()
class BATTERYCOLLECTOR_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;
	// Return the mesh for the pickup
	FORCEINLINE class UStaticMeshComponent* GetMesh() const { return PickupMesh; }

	// Return whether or not the pickup is active
	UFUNCTION(BlueprintPure,Category = "Pickup")
	bool IsActive();

	// Allows other classes to safely change whether or not the pickup is active
	UFUNCTION(BlueprintCallable, Category = "Pickup")
	void SetActive(bool NewPickupState);
	
protected: // protected = this can be changed only through this script,through BPS or through another script based on this one
	// True when the pickup can be used and false when the pickup is deactivated
	bool bIsActive;

private:
	// Static mesh to represent the pickup in the level
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Pickup", meta = (AllowPrivateAccess = "true"))
	class UStaticMeshComponent* PickupMesh;


};

Any ideas? :smiley:

You might be missing the #include "Components/StaticMeshComponent.h" in the .cpp file. Apparently the CoreMinimal header doesn’t include actor components.

Hey ! Good news, I see what the problem is !

class UStaticMeshComponent

Class keywork is a forward declaration, to avoid having many .h includes in your class header. ( and avoid circular ref )

but then in .cpp you have to include the .h so here you are missing the .h of UStaticMeshComponent

which is:

#include "Components/StaticMeshComponent.h"

It should work fine now ! :slight_smile:
Have a good day !