Class declaration into a header?

Hello, I’ve seen the following code in a EnemyManager.h file:

#include "CoreMinimal.h"
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "EnemyManager.generated.h"

class ABaseEnemy;

class CPPINHERITANCE_API AEnemyManager : public AActor


	TSubclassOf<ABaseEnemy> GetRandomEnemyClass() const;


I don’t understand what this does

class ABaseEnemy

mean. Because if you just do a

#include "ABaseEnemy.h"

it works perfectly too.

What am I missing here?.(I’m also new to C++)


If you include a header file, you copy everything in that file at the position where the include statement is.
Just writing

Class classname;

Means you are declaring the class, so you are telling the compiler „this class does exists“ and you would use this if you only need the class as a datatype in the file, because that way you are not including the entire head file.

This is called forward declaration, you declare incomplete class for type to work in header file, later it is properly declared in different include in cpp file (note that true function of #include is pasting content of the file to another file and fact that header files alone are never compiled on there own they are used in compilation of cpp files) if type is really used in cpp file, otherwise you will get use of incomplete type error. This is to avoid circular dependency in header files which may cause issues, if possible you should avoid including header file other then one containing base class of class you declaring, and forward declaration is one of methods to avoid that.

You can read about it here: