Why is my USTRUCT causing a weird syntax error?

I’m trying to create a custom struct, to ensure I understand the syntax:

UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class LEARNINGPROJECT_API UTestComp: public UActorComponent
{
	GENERATED_BODY()

public:	
	// Sets default values for this component's properties
	UTestComp();

	// Called when the game starts
	virtual void BeginPlay() override;
	
	// Called every frame
	virtual void TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction ) override;

	FTestStruct myStruct;
	
};


USTRUCT()
struct LEARNINGPROJECT_API FTestStruct{


	GENERATED_USTRUCT_BODY()

	UPROPERTY()
	float testFloat;
};

I don’t get any errors within the struct declaration itself, but I get four errors on the “FTestStruct myStruct;” line, two identical pairs of:
Missing ‘;’ before identifier ‘myStruct’
missing type specifier-int assumed.

I’m assuming this has something to do with my messing up the struct declaration, but the syntax looks like it matches the tutorial I was following at A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums , so I’m not sure where I should begin debugging.

Move the the order of declerations. Arrange it like below

 USTRUCT()
 struct LEARNINGPROJECT_API FTestStruct{
 
 
     GENERATED_USTRUCT_BODY()
  
     UPROPERTY()
     float testFloat;
 };

 UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
 class LEARNINGPROJECT_API UTestComp: public UActorComponent
 {
     GENERATED_BODY()
 
 public:    
     // Sets default values for this component's properties
     UTestComp();
 
     // Called when the game starts
     virtual void BeginPlay() override;
     
     // Called every frame
     virtual void TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction ) override;
 
     FTestStruct myStruct;
     
 };

Remember this is C++! Order matters!!

That works! Thank you very much… I keep reflexively thinking of it like C#, where you can basically scrawl declarations anywhere and trust the compiler to work out what you’re doing. :slight_smile: