Download

I included the right header. Why is the identifier undefined?

New C++ programmer here. I’m trying to make this class, but I’m running into problems. It won’t compile because the function RandomizeWorld needs a pointer to an AHXWorldBuilder, but AHXWorldBuilder is apparently undefined.

HXWorldRandomizer.h

#pragma once

#include "CoreMinimal.h"
#include "UObject/NoExportTypes.h"
#include "HXWorldBuilder.h"
#include "HXWorldRandomizer.generated.h"

UCLASS()
class HXGAME_API UHXWorldRandomizer : public UObject
{
	GENERATED_BODY()
public:
	virtual void RandomizeWorld(AHXWorldBuilder* WorldBuilder);
};

Visual Studio suggests that I need to add #include "HXWorldBuilder.h" to my code, but it’s already in there. Any ideas where I should look to see why this won’t compile? HXWorldBuilder.h has #include "HXWorldRandomizer.h". It’s not a problem for header files to include each other, is it?

Including headers in headers is fine. Maybe you’ve put the AHXWorldBuilder class into a folder inside your root source folder? If so, you have to update the include path for it. For example:

/// MyActor.h is in Source/MyProjectName/MyTestFolder/

// include path is wrong (not going to compile)
#include "MyActor.h"

// fixed include path
#include "MyTestFolder/MyActor.h"

With that said, in most cases you can get away with only forward declaration of types in header. Instead of including the header (making compile times longer), you can tell the compiler what that type is (class? struct?).

// you can put this above the UCLASS macro for example
class AHXWorldBuilder;

// this is also valid
virtual void RandomizeWorld(class AHXWorldBuilder* WorldBuilder);
1 Like

Thanks so much! The headers are all in the same folder, and other headers are able to see each other. For some reason this one just wasn’t working. I’m not sure why. But the forward declaration you recommended worked just fine. I’ll try to do that from now on.