How to fix a Syntax Error on variable declaration of custom class?

You should read up on UObjects and the reflection system (UPROPERTY, UFUNCTION, etc).

UE4 Relection System blog entry

I wasn’t commenting on your formatting, either of your statements above are fine. What is important is that any UObject member variables of a class must be marked as UPROPERTY otherwise your memory will be freed up by the engine. UObject memory management is done by garbage collection and it only knows the object is in use if it can follow UPROPERTY variables. There are internal lists of objects and if other objects don’t tell that main list they are using something via UPROPERTY the object will be removed out from under you.

There are lots of powerful things that require UPROPERTY. You don’t have to mark every variable as one, but if you want to replicate over the network, save to disk, edit the value in the editor, debug print variable state, etc you must have them marked.

Some other links I’ve shared in the past

Intro C++ in UE4

Understanding MyClass.generated.h files

Programming Docs

Objects/Actors/Framework

Programming Quick Start

Replication