I’ve run into an issue with cyclic dependency. Specifically, character needs to reference inventory, inventory also needs to reference character. I don’t think there’s any way to break this dependency without a lot of trouble either.
Right now, Inventory.h includes MyCharacter.h, MyCharacter.h includes inventory.h. The error given is “Class MyCharacter DependsOn(Inventory) is a circular dependency.” The way I see suggested to break this, and I’ve done before in pure C++, is to use forward declaration so the compiler knows that the class exists before it reaches the appropriate header file. Doing this changes nothing. Since there’s no VS error code, and it’s listed as “OtherCompilationError”, I’m pretty sure that it’s specifically a problem with the header files, and not actually with the classes.
This just makes me think I’m including files incorrectly. I tried looking at the sample shootergame to see how they do it. They have the same cycle with the character class referencing weapon and vice versa, but there’s almost no include files. Instead, there’s #include "ShooterGameClasses.h"
in ShooterGame.h, and ShooterGame.h is included from other classes. ShooterGameClasses.h does not exist. Googling suggests that it’s generated by the UnrealHeaderTool, but I can’t find any specifics of what exactly it does. A -classes.h file does exist in my project, but is nearly blank:
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
/*=============================================================/*===========================================================================
C++ class boilerplate exported from UnrealHeaderTool.
This is automatically generated by the tools.
DO NOT modify this manually! Edit the corresponding .h files instead!
===========================================================================*/
#pragma once
This is the entirety of that class. I’m assuming that UHT is supposed to look over all of my classes and automatically add #includes in here, then I just #include this generated file.
If that is the case, why isn’t UHT putting anything into this file? Is there something I need to do to manually run UHT and let it find my classes, beyond pressing “Compile” in Visual Studio? That sounds like it would resolve the specific issue of the cyclic include files, but what about the cyclic classes?
If this isn’t the case, then what is the proper way to resolve the cyclic include files and classes?