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"

Syntax Error when using accepting an Enum as a param

I have defined an enumeration at the top of a UQuakeWeapon.h file that looks like this:

 enum class EAmmoType : uint8
     ENone       UMETA(DisplayName="None"),
     EShell      UMETA(DisplayName="Shells"),
     ENail       UMETA(DisplayName="Nails")

I have a series of ammo integers in my player class, and I'm trying to have a weapon call a GetAmmo method in the player class when fired. The GetAmmo() and SetAmmo() methods in the header look like this:

 int32 GetAmmo(EAmmoType ammoType);
 void SetAmmo(EAmmoType ammoType, int32 value);

However, when I compile this code, Unreal throws:

 syntax error: identifier 'EAmmoType'

on both of those methods. The player header class includes the UQuakeWeapon.h. I'm not sure why Unreal is throwing a syntax error here.

Product Version: UE 4.12
more ▼

asked Aug 15 '16 at 11:39 PM in C++ Programming

avatar image

Zero One
91 9 7 13

avatar image Doug E ♦♦ STAFF Aug 16 '16 at 07:07 PM

If I understand your setup correctly, you are defining your enum in your weapon class and calling the functions (which take your enum as a parameter) in your character class, is that correct? Was a definition for the two classes added to the Character.cpp file? Is there a reference to EAmmoType anywhere else in the project? Can you provide the full output log from Visual Studio?

avatar image Zero One Aug 16 '16 at 07:24 PM

I'm defining the enum above the UCLASS() macro in my weapon header, and those functions exist in my character class, which has an #include "UQuakeWeapon.h" statement. EAmmoType is not referenced anywhere else, other than UQuakeWeapon.cpp and UQuakeCharacter.h/cpp. Visual Studio produces this pastebinned output.

It does occur to me that UQuakeCharacter.h includes UQuakeWeapon.h, and UQuakeWeapon.h includes UQuakeCharacter.h. Could a circular dependency be causing this error? I'm not sure if it is, because they've included each other for a long time, and so far, the project has been compiling fine.

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

1 answer: sort voted first

Circular dependency appears to be the most likely cause of the compile errors. Without seeing the setup of your classes, the best solution would be to remove the include statement from one class and replace it with a forward declaration for the necessary class. In this case I would try removing the Character class include from your Weapon class and use class AUQuakeCharacter instead.


Doug Wilson

more ▼

answered Aug 16 '16 at 07:48 PM

avatar image Zero One Aug 16 '16 at 08:06 PM

Yep, that fixed it! I knew the circular dependency had existed for a while, but it seemed to compile fine before now. I'll watch out for them in the future.

Only downside is I now need to include the UQuakeCharacter header in all of my weapon CPPs. But hey, at least it compiles!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
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