# Forward Declare Structs???

**URL:** <https://forums.unrealengine.com/t/forward-declare-structs/115559>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [August 27, 2018, 5:20pm UTC](https://forums.unrealengine.com/t/forward-declare-structs/115559 "2018-08-27T17:20:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_3115cf58](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_3115cf58](https://forums.unrealengine.com/u/anonymous_user_3115cf58)\
**Post date:** [August 27, 2018, 5:20pm UTC](https://forums.unrealengine.com/t/forward-declare-structs/115559/1 "2018-08-27T17:20:22Z")

</div>

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  
//========================

---

<div class="post-metadata">

**Author:** ![StefanHohnwald](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@StefanHohnwald](https://forums.unrealengine.com/u/StefanHohnwald)\
**Post date:** [August 27, 2018, 5:52pm UTC](https://forums.unrealengine.com/t/forward-declare-structs/115559/2 "2018-08-27T17:52:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_3115cf58](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_3115cf58](https://forums.unrealengine.com/u/anonymous_user_3115cf58)\
**Post date:** [August 27, 2018, 6:31pm UTC](https://forums.unrealengine.com/t/forward-declare-structs/115559/3 "2018-08-27T18:31:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_3115cf58](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_3115cf58](https://forums.unrealengine.com/u/anonymous_user_3115cf58)\
**Post date:** [August 27, 2018, 6:39pm UTC](https://forums.unrealengine.com/t/forward-declare-structs/115559/4 "2018-08-27T18:39:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Manoel.Neto](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/manoel.neto/32/1210013_2.png) [@Manoel.Neto](https://forums.unrealengine.com/u/Manoel.Neto)\
**Post date:** [September 3, 2018, 2:08pm UTC](https://forums.unrealengine.com/t/forward-declare-structs/115559/5 "2018-09-03T14:08:48Z")

</div>

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.
