My header file??

Hey folks! I am having a weird issue with a header file and am unsure what occurred. I keep getting this error from the compiler:
syntax error: missing ‘;’ before ‘*’

I have no idea what happened… I started trying to test some new code, then started getting this error and whatever I do I can’t get it to go away… The line (59) that it is complaining about is this:


   line55  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Internal")
               USoundBase* UFireSound;

              UPROPERTY(BlueprintReadOnly, Category = "Internal")
  line59   AZephyrCharacter* ACharacter;                  This is the line that has an issue

I even copy pasted old code from a previous back up and am still getting the same issue… What the heck? Everything was fine before, and I have removed the code that I was testing… Any help is much apreciated!

Compiler also complains missing type specifier - int assumed.

And

Unexpected tokens proceeding ‘;’

Edit: I realize using ACharacter as a variable name is a bad idea, so I have changed it, but I still get the same compiler error… Missing ; before *… I’m so lost… This worked before!

Your header file is not recognizing AZephyrCharacter as a class. Forward declare AZephyrCharacter. Right after your includes, put:

class AZephyrCharacter;

Is there a reason why this has happened?

Thank you very much for the help by the way Kelby! That worked perfectly… Sorry for my blunt response yesterday, I was having a rough night with all this corona **** going on… With that said, is there something I did to cause this to be an issue? Previously I did not have to forward declare the reference. And it was literally with the same class.

Edit:
Guess I will never know… :confused: Thanks for the help anyways bud!

Hey Darkloud, it’s hard to say without seeing the full header file you’re writing.

My best guess is that somehow you no longer include the file that declares AZephyrCharacter, but if you feel comfortable sharing the full file I could take a look at it and see if I can find the reason!

Darkloud1989, I’m sorry that I missed your follow-up question back in March. I didn’t read any bluntness in your question at all, I just was absent from the forum. :wink:

As for why this happened, I’m not an expert, but here’s my very un-expert understanding:

Because of UE4’s “include what you use” approach, the compiler that is compiling a header file is completely unaware of any other classes you have created, so it does not know what they are and won’t recognize them when you try to declare an instance of some other custom class. The only way the compiler will know anything about other classes is for you to forward-declare the class or have a “#include” at the beginning of the file.

In your code, when the compiler reached line 59, the first thing it saw was the word “AZephyrCharacter”. You and I know that you were declaring an instance of the class AZephyrCharacter. However, the compiler did not know of such a class. My non-expert understanding is that, in such a situation, the compiler takes a guess about what you are trying to do, and it generally guesses wrong. Specifically, when the compiler sees a name it does not recognize, it assumes you are declaring an integer with that name. So, it assumed “AZephyrCharacter” was an integer with the name “AZephyrCharacter.” Having made that assumption, it expected to see one of two things that follow the name when you declare an int – either (a) an initialization (i.e., an equals sign followed by a number), or (b) a semi-colon. In your line 59, it didn’t see either of those things. Instead, it saw an asterisk followed by the word “ACharacter,” which is not something the compiler understands immediately after an integer name. Again, I’m no expert, but think that in the absence of a forward declaration of a #include, the compiler read your original line 59 the same way it would read the following:

int32 MyInteger* SomeRandomWord;

In your line 59, you used the word “AZephyrCharacter” instead of the name “MyInteger,” but the compiler reads it the same way. You also used an asterisk and the word “ACharacter” instead of “*SomeRandomWord,” but the compiler doesn’t understand that syntax either way, and should always give you this error.

By forward declaring the class (or putting an #include of the class at the beginning of your header), you are now alerting the compiler to the fact that AZephyerCharacter is not the name of an integer you are declaring, but is instead the class of a variable you are declaring, and specifically a pointer variable with the name “ACharacter.”

Your follow-up post suggests that maybe you didn’t have this problem before? That sounds strange to me. If you didn’t forward-declare the class or #include it, then the compiler should have given you this error; the compiler should not be recognizing classes that you haven’t forward declared or included.

I hope this answers your question and is helpful. If I misunderstood your question, please let me know and I’ll take another stab at it.

Good luck with your game!