I have a header containing a bunch of enums, structs etc. This is where the enum is I want to use. However this header includes the class itself (as it’s referenced in one of the structs). So importing it into the class causes a circular reference.
However even with an engine enum such as EAIForceParam and including AITypes.h (where it’s located) causes the error.
I’m pretty new to C++ and been awake for 24 hours so bear with me here
You need to use forward declarations, since your compiler is runnning into circular dependencies and to avoid that your compiler skips the include to not to be included again thanks to the #pragma once macro
You need to move your include directives in to the CPP file and in your include use forward delcrations.
Hi,
I had the same problem on 4.22 Unreal version.
The error: “Expected the name of a previously defined enum” isn’t caused by a missing include file because it is not a C++ compiler error but it is an Epic HeaderTool error.
Basically if you define a UENUM in a Header file without define any USTRUCT or UCLASS the HeaderTool doesn’t parse that file, so the UENUM definition will not be stored in the object hash list.
Possible solutions (until Epic GenerateProjectFiles fix)
Move the UENUM declaration in a Header file where there are some USTRUCT or UCLASS declaration
I ran into this same error today even though the syntax was correct after triple-checking it all over. I tried forward declarations and that did not work. I did notice that Visual Studio stopped colorizing the tags in my code, so I decided to try something that fixed other issues I’ve had…
If time isn’t a constraint, try:
Close UE4 and Visual Studio
Delete Binaries and Intermediate Folders
Right-click *.uproject file and generate new Visual Studio project files