UBehaviorTree question

Sorry for the stupid question… (I am very new to cpp
In the header file of the ShooterAIController, we have ‘class’ in front of UBehaviorTree.
Why we need the ‘class’?
Is it a forward declaration? Is it the same as that we put ‘class UBehaviorTree’ just below the includes? If yes, why we don’t need to include #include “BehaviorTree/BehaviorTree.h” in the cpp file?

private:
	UPROPERTY(EditAnywhere)
	class UBehaviorTree* AIBehavior;
1 Like

Yes.

If it compiles then that would mean it was included somewhere in the chain of includes. I would suggest you always include what you’re using in the .cpp’s anyway.

1 Like

I found it still compiles successfully without the ‘class’ in front of UBehaviorTree.
Does this mean actually we don’t need it or it is better to have it?

As long as there’s no errors then it’s fine. You can still use a forward declaration if you want, it doesn’t matter. It’s not going to change anything by having a forward declaration when it’s not needed.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms