Download

Forward Declare Structs???

How do you forward declare structs from another class? I have found no way to do this as I am fairly new to C++ in UE4.
I have a USTRUCT in an Inventory System Library Class called FBaseItemData. I need to(due to circular dependency) forward
declare that struct in a Master Item Class. But I have no idea how to do this. Some help would be great. I have forward declared the base
class in the Master Item Class but as soon as I add the UPROPERTY() macro above the FBaseItemData which is forward
declared the compiler freaks out. I’m just so stuck so any help would be great.

//============================
// CLASS FORWARD DECLARATIONS
//============================
class UInventory_System_Library;
struct FBaseInventoryItemData;
//===============================================
// MASTER INVENTORY ITEM CLASS DEFINITION
//===============================================

UCLASS(Blueprintable)
class QUEST_ELTALE_KINGDOM_API UMaster_Inventory_Item : public UPlayer_Character_Library
{
GENERATED_BODY()
//This declaration forward declares the Inventory System Library Class.
UInventory_System_Library* Inventory_System_Library_FD_Class;

public:
//====================================
//HOW DO I FORWARD DECLARE THE STRUCT???
//==========================================
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = “Test”)
FBaseInventoryItemData* Waaaaaa = Boo;

};

//========================
// END OF SCRIPT
//========================

What exactly is the compiler error? Is is something like
“error : Inappropriate ‘*’ on variable of type ‘FBaseInventoryItemData’, cannot have an exposed pointer to this type.” ?

As far as i know you can’t have a pointer to a struct/USTRUCT if you declare it a UPROPERTY.
If you want to use pointers and UPROPERTY/Blueprint access, use UObjects, otherwise you need to use the struct as a reference or a “full” (non-pointer/non-reference) class member.

Its coming up with the struct not being a valid type and needs to be a UENUM,USTRUCT etc etc and both my classes derive from UObject as well.

And if you cant declare it in the header file is it possible to declare a variable in the .cpp file at all?

You can’t forward declare a struct that is used as a non-pointer (since the size of the struct must be known at compile time) and you cannot tag a struct pointer as UPROPERTY, so you must put that struct on a .h file and include it in your header.