What is Super class and when exactly I use it?

I know it may seems a very noob question, But really I spent a lot of hours to find out what and when I use Super class

there is examples I Could understand such as Super::BeginPlay();
but what I couldn’t understand why we used it like so Super::PostInitProperties(); or Super::PostEditChangeProperty()

however there is no problem with me understanding the API itself, But still “Super” can’t understand it’s specific use exactly .or what does it mean?

Help please

thanks

This is something basic of C++.

If you have a BaseClass where you defined a virtual function and gave it some logic, and you create a child class from it where you override this functions, you can make sure that the BaseClass code is still called by calling “Super::Function()”.

5 Likes

Are you sure? I’m new to C++ but after some quick googling around I can’t find any reference to Super:: being a C++ standard feature.

1 Like

Yes i’m sure. Super:: itself is not basic C++. In C++ you would go with

void ChildClass::Foo()

{

    BaseClass::Foo();        

}

But in UE4 we just use Super::Foo();

8 Likes

thanks a lot

Thanks also from me.

1 Like

Super is very important for inheriting basic functionality from a parent class. Use it extensively, if you want to save yourself the time.

1 Like

UE support this by using typedef

262936-15453106912245.png

It’s cool

5 Likes

void AClassSample::BeginPlay()
{
Super::BeginPlay(); // we call default begin play from Super class
// But for what? Default Begin Play Function contains
// Some methods, that are neccessarry to execute it as
// actually BeginPlay function. but when we override it,
// all the functionality of default BeginPlay disappears.
// Because of overriding, we need at first to call default
// BeginPlay function, to include default function logic,
// and then do the rest of things.
}

2 Likes

void AClassSample::BeginPlay()
{
Super::BeginPlay(); // we call default begin play from Super class
// But for what? Default Begin Play Function contains
// Some methods, that are neccessarry to execute it as
// actually BeginPlay function. but when we override it,
// all the functionality of default BeginPlay disappears.
// Because of overriding, we need at first to call default
// BeginPlay function, to include default function logic
// from Super class, and then do the rest of things.
}

Good followup - as the accepted answer described what super is generically in programming, but doesn’t exist in standard c++ because of multiple inheritance ambiguity. Hence OP’s long fruitless search.

A macrofied class system like UE has can however safely mimic it with a typedef.

1 Like

Why we want to call base class function ? What is the purpose of it ?

Because in some cases we want to allow the engine to do a lot of things and to follow its logical flow.
Two messages above yours, NkIceberg went through explaining Super::BeginPlay() as an example.

It IS cool