How can I resolve these compiler errors?

Hi there,

I recently tried using C++ with ue4 again after not doing it for a while, since I had problems last time and never got around to solve those problems. Now, I followed the “Intro to Programming” video to get into the programming part, but when I type exactly the same code(except for the “VisibleAnywhere” parameter), I get a bunch of errors which are unlogical.

Powerup.h:

#pragma once

#include "GameFramework/Actor.h"
#include "Powerup.generated.h"

/**
 * 
 */
UCLASS()
class APowerup : public AActor
{
	GENERATED_UCLASS_BODY()

	UProperty(VisibleAnywhere, Category = Powerup) 
	   TSubjectPtr<USphereComponent> TouchSphere;

	UProperty(VisibleAnywhere, Category = Powerup)
		float RotationRate;

	virtual void Tick(float DeltaTime) OVERRIDE;
	
};

Powerup.cpp:

#include "Pizza.h"
#include "Powerup.h"


APowerup::APowerup(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
	PrimaryActorTick.bCanEverTick = true;

	TouchSphere = PCIP.CreateDefaultSubobject<USphereComponent>(this, TEXT("TouchSphereComponent"));
	TouchSphere->SetSphereRadius(20.0f, false);
	RootComponent = TouchSphere;

	RotationRate = 180.0f;

}

void APowerup::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	FRotator MyRot = GetActorRotation();
	MyRot.roll += RotationRate * DeltaTime;
	SetActorRotation(MyRot);
}

And here are the errors:

Error	1	error C2061: syntax error : identifier 'VisibleAnywhere'	 projects\pizza\source\pizza\Powerup.h	16	1	Pizza
Error	2	error C3646: 'TSubjectPtr' : unknown override specifier	 projects\pizza\source\pizza\Powerup.h	16	1	Pizza
Error	3	error C2143: syntax error : missing ';' before '<'	 projects\pizza\source\pizza\Powerup.h	16	1	Pizza
Error	4	error C4430: missing type specifier - int assumed. Note: C++ does not support default-int	 projects\pizza\source\pizza\Powerup.h	16	1	Pizza
Warning	5	warning C4183: 'UProperty': missing return type; assumed to be a member function returning 'int'	 projects\pizza\source\pizza\Powerup.h	16	1	Pizza
Error	6	error C2059: syntax error : '<'	 projects\pizza\source\pizza\Powerup.h	16	1	Pizza
Error	7	error C2238: unexpected token(s) preceding ';'	 projects\pizza\source\pizza\Powerup.h	16	1	Pizza
Error	8	error C2061: syntax error : identifier 'VisibleAnywhere'	 projects\pizza\source\pizza\Powerup.h	19	1	Pizza
Error	9	error C2144: syntax error : 'float' should be preceded by ';'	 projects\pizza\source\pizza\Powerup.h	20	1	Pizza
Error	10	error C4430: missing type specifier - int assumed. Note: C++ does not support default-int	 projects\pizza\source\pizza\Powerup.h	20	1	Pizza
Error	11	error C2535: 'int APowerup::UProperty(void)' : member function already defined or declared	 projects\pizza\source\pizza\Powerup.h	20	1	Pizza
Warning	12	warning C4183: 'UProperty': missing return type; assumed to be a member function returning 'int'	 projects\pizza\source\pizza\Powerup.h	20	1	Pizza
Error	13	error C2065: 'TouchSphere' : undeclared identifier	 Projects\Pizza\Source\Pizza\Powerup.cpp	12	1	Pizza
Error	14	error C2065: 'TouchSphere' : undeclared identifier	 Projects\Pizza\Source\Pizza\Powerup.cpp	13	1	Pizza
Error	15	error C2227: left of '->SetSphereRadius' must point to class/struct/union/generic type	 Projects\Pizza\Source\Pizza\Powerup.cpp	13	1	Pizza
Error	16	error C2065: 'TouchSphere' : undeclared identifier	 Projects\Pizza\Source\Pizza\Powerup.cpp	14	1	Pizza
Error	17	error C2039: 'roll' : is not a member of 'FRotator'	 Projects\Pizza\Source\Pizza\Powerup.cpp	25	1	Pizza
Error	18	error C2061: syntax error : identifier 'VisibleAnywhere'	 Projects\Pizza\Source\Pizza\Powerup.h	16	1	Pizza
Error	19	error C3646: 'TSubjectPtr' : unknown override specifier	 Projects\Pizza\Source\Pizza\Powerup.h	16	1	Pizza
Error	20	error C2143: syntax error : missing ';' before '<'	 Projects\Pizza\Source\Pizza\Powerup.h	16	1	Pizza
Error	21	error C4430: missing type specifier - int assumed. Note: C++ does not support default-int	 Projects\Pizza\Source\Pizza\Powerup.h	16	1	Pizza
Warning	22	warning C4183: 'UProperty': missing return type; assumed to be a member function returning 'int'	 Projects\Pizza\Source\Pizza\Powerup.h	16	1	Pizza
Error	23	error C2059: syntax error : '<'	 Projects\Pizza\Source\Pizza\Powerup.h	16	1	Pizza
Error	24	error C2238: unexpected token(s) preceding ';'	 Projects\Pizza\Source\Pizza\Powerup.h	16	1	Pizza
Error	25	error C2061: syntax error : identifier 'VisibleAnywhere'	 Projects\Pizza\Source\Pizza\Powerup.h	19	1	Pizza
Error	26	error C2144: syntax error : 'float' should be preceded by ';'	 Projects\Pizza\Source\Pizza\Powerup.h	20	1	Pizza
Error	27	error C4430: missing type specifier - int assumed. Note: C++ does not support default-int	 Projects\Pizza\Source\Pizza\Powerup.h	20	1	Pizza
Error	28	error C2535: 'int APowerup::UProperty(void)' : member function already defined or declared	 Projects\Pizza\Source\Pizza\Powerup.h	20	1	Pizza
Warning	29	warning C4183: 'UProperty': missing return type; assumed to be a member function returning 'int'	 Projects\Pizza\Source\Pizza\Powerup.h	20	1	Pizza
Error	30	error : Failed to produce item:  Projects\Pizza\Binaries\Win64\UE4Editor-Pizza-Win64-Debug.pdb	 Projects\Pizza\Intermediate\ProjectFiles\ERROR	Pizza
Error	31	error MSB3073: The command "D:\UnrealEngine\Github\UnrealEngine\Engine\Build\BatchFiles\Build.bat PizzaEditor Win64 Debug " Projects\Pizza\Pizza.uproject"" exited with code -1.	C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.MakeFile.Targets	38	5	Pizza

Thanks!!

That actually solved all the problems, except for it’s “MyRot.Roll”, not “.roll”, and I mistyped TSubobjectPtr once. Now the code finally compiles with no errors! :slight_smile:

Hi ,

One thing that I noticed is that you used UProperty instead of UPROPERTY in your header. Try changing the two lines with

UProperty(VisibleAnywhere, Category = Powerup)

to

UPROPERTY(VisibleAnywhere, Category = Powerup

Please let us know if that helps to resolve the compile errors that you received.