Missing 'public' in Class declaration

I’m trying to create my own character movement component where gravity is dynamic in c++.
What I did was extend or parent from pawn movement component. Initial compile (when nothing was still inside the .h and .cpp) worked fine. But when I pasted the codes on my class it’s giving me this error:

CompilerResultsLog:Error: Error C:/pathtofile/Unreal Projects/Gravity3d/Source/Gravity3d/Public/GravityMovementComponent.h(1) : Error: Missing 'public' in Class declaration

It says that the error is in line 1 of the header file but I don’t have a Class declaration there.

This is the lines on my header file:

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "AI/Navigation/NavigationAvoidanceTypes.h"
#include "AI/RVOAvoidanceInterface.h"
#include "Animation/AnimationAsset.h"
#include "Engine/EngineBaseTypes.h"
#include "Engine/EngineTypes.h"
#include "GameFramework/PawnMovementComponent.h"
#include "Interfaces/NetworkPredictionInterface.h"
#include "WorldCollision.h"
#include "GameFramework/RootMotionSource.h"
#include "GravityMovementComponent.generated.h"

class FDebugDisplayInfo;
class AGravityCharacter;
class UGravityMovementComponent;

Thanks for your time.

Hi zbrtcchr ,

My guess it that it is throwing up that error due to #include "GravityMovementComponent.generated.h" which I think should only be included if there is a class declaration. Remove it and see if it then compiles?

Hope that helps. Cheers,

Sorry. That didn’t work for me. I commented out that line and it is still giving me the same error.

CompilerResultsLog:Error: Error C:/PathToFile/Unreal Projects/Gravity3d/Source/Gravity3d/Public/GravityMovementComponent.h(1) : Error: Missing 'public' in Class declaration

Is this possibly a follow up error? It is important to always look at the first error message in log. Or are there additional note: lines below the error message? Could you post the complete build log?

Sorry for the late reply and thank you for your time. It is actually the first error in log. There are no note lines and the next error is due to the first class not being able to compile.
link text
Attached is the output log.

This is not a compiler error, it is a UHT (Unreal HEader Tool) error. The UHT parses the C++ code before the compiler does. The UHT still has many restrictions, and I believe this is one of them.

Is there any reason that you not declare the class UGravityMovementComponent in the header? It is not clear what you are intending to do with this header.

That is the header file. and I already declared the class like this.

`UCLASS()
class GRAVITY3D_API UGravityMovementComponent : public UPawnMovementComponent, public IRVOAvoidanceInterface,
{
GENERATED_BODY()
public:

};`

I’m trying to replicate the CharacterMovementComponent but with custom gravity.

Alright! Got through it! As you can see on the latest code that I replied with there is an extra coma ‘,’ after the public IRVOAvoidanceInterface.

Thanks for the time. What you told me about UHT got me on the right track and is a new lesson learned. Thanks again!

It confuses me, because you wrote in your question that you don’t have any class declaration in the header. And the posted header code only shows a forward declaraion of that class. So maybe you can update the question with the complete GravityMovementComponent.h header?.
Also check that you include the header in your GravityCharacter.h.

Oh. Sorry if it confused you. I said that the error indicated that the error was in line 1 of the header file but I don’t have a Class declaration there. My class declaration was on line 125.

So I just posted the top few lines of my header file because the error was only in line 1. Everything is fine now, anyway.

I got the similar error last night, which I defined my class as

UCLASS()
class MYGAME_API MyClass : AInfo {
  GENERATE_BODY()
  public:
     MyClass();
    ~MyClass();
}

And I fixed that by adding

Class MyGAME_API MyClass: public AInfo {
}

In my class decleration. I hope it helps :slight_smile:

1 Like

I’ve already fixed mine but it had a different solution. It was, after all, only a syntax error in my class. But thanks for the time!

Necroing this post because I encountered this issue today and figured out why it occured in my case.

The issue in my case was that I had a struct with a UCLASS macro above it, which obviously should not be the case (and instead should be a USTRUCT macro).