Forward Declaration

Hello, guys so I am new to C++ and I am trying to get the concept of Forward Declaration to work. I have forward declared my Inventory System Library class within a Master Inventory Item Class. I need to declare a new variable in the master inventory item class which is based on a struct type that is present in the Invntory system Library Class which I have forward declared. This however gives me a message that says the type is undeclared and must be a UCLASS, UENUM etc etc. I need serious help with this.

//================================
// HEADER INCLUDES
//================================
#pragma once
#include “Player_Character_Library.h”
#include “Master_Inventory_Item.generated.h”

//============================
// CLASS FORWARD DECLARATIONS
//============================
class UInventory_System_Library;

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

};

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

AS YOU CAN SEE I WANT TO GET A STRUCT TYPE FROM UInventory_System_Library AND DECLARE IT IN THE MASTER INVENTORY ITEM CLASS WHERE THIS SCRIPT IS FROM.

Where is your class UInventory_System_Library; full declaration?

I suspect you have missed an include maybe?

I have to forward declare my Inventory System library in the master inventory item class because they need to reference each other. If I don’t forward declare I get circular dependency problems. You see my inventory system library contains a struct that has a pointer to the master inventory item class, but I also need to include that same struct in the master inventory item class. If I don’t forward declare it causes circular dependency issues.

I need to declare the FBaseInventoryItemData struct which is inside the Inventory_System_Library inside of the Master Inventory Item Class. Im not sure how you pull variable types out of forward declared classes.

Also do you know any tips to avoid circular dependencies all together?

I get the need for forward declaration but I’m a bit in the dark about your dependencies as a whole.

What I was asking is which header file does include your UInventory_System_Library declaration and where is this header file included?

I’m starting to think you over-complicate the things a bit. Try removing the forward declaration and include the UInventory_System_Library header instead.

Can you share your code ? At least the class definition and includes ? It would help figure out whats wrong.