Constructor formatting

I’m currently looking through the gameplay programming documentation, specifically for the constructors.

The most basic form of a UObject constructor is shown below.

AMyClass::AMyClass(const FPostConstructInitializeProperties& PCIP)
    : Super(PCIP)
{
}

Simple enough. I’m not sure of what the “Super” means though. It appears as though it’s extending from another class, just as extending is done in C#.) ie- Class foo : bar , where class foo is extending class bar.

Which class is “Super?”

I’ve noticed that it looks the same way in actual classes, too.

ASideScrollerCharacter::ASideScrollerCharacter(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{

In the next example, the syntax uses “const class”, which obviously declares a constant class, which cannot be changed.

AUDKEmitterPool::AUDKEmitterPool(const class FPostConstructInitializeProperties& PCIP)

Why does this example (and the character from SideScroller both use class, whereas the first example does not?

Super is a typedef that is autogenerated as part of the header generate process. It is simply an alias for the parent class.

So if your class definition is class ASideScrollerCharacter : public ACharacter, then Super for ASideScrollerCharacter class is ACharacter.

The use of class in the two examples you have there is unnecessary and probably results from copy/paste or Visual Assist auto-completion. The purpose of putting the class keyword in front of a type definition in C++ is to tell the compiler that the type is a class type, referred to as forward declaring the type.

This can be necessary when dealing with header include order. Because the compiler doesn’t need to know any details about the class unless it is trying to call a function or access a member variable it is enough to simply say this is a class and the compiler can put the appropriate amount of memory aside for a pointer. Most frequently this would be needed in a header for a member variable or function parameter declaration.

Excellent answer Marc, it helped clarify things for me.

Thank you.

"Which class is “Super?” "

The super class is ultimately UClass

You should check out class.h

UClass(const class FPostConstructInitializeProperties& PCIP);

PCIP is used to create new sub objects within the constructor:

// Create a follow camera
FollowCamera = PCIP.CreateDefaultSubobject(this, TEXT("FollowCamera"));
Components.Add(FollowCamera);

// Create a camera boom (pulls in towards the player if there is a collision)
	
CameraBoom = PCIP.CreateDefaultSubobject(this, TEXT("CameraBoom"));
CameraBoom->AttachTo(RootComponent);
	
Components.Add(CameraBoom);

:slight_smile:

Have fun!

Rama