x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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.

Product Version: UE 4.20
Tags:
more ▼

asked Aug 27 '18 at 02:22 PM in C++ Programming

avatar image

KyleMason
11 1 2 5

avatar image KyleMason Aug 27 '18 at 02:24 PM

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

avatar image dZh0 Aug 27 '18 at 02:42 PM

Where is your class UInventory_System_Library; full declaration?

I suspect you have missed an include maybe?

avatar image KyleMason Aug 27 '18 at 03:38 PM

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.

avatar image KyleMason Aug 27 '18 at 03:40 PM

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.

avatar image KyleMason Aug 27 '18 at 03:41 PM

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

avatar image dZh0 Aug 27 '18 at 04:00 PM

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.

avatar image val59000MC Aug 27 '18 at 06:51 PM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question