Calling Super

When I override functions that are derived from the engine classes, do I need to call Super in some way? (If not it doesn’t make sense)

If so, how?

If the functions return a value and you want to access the base value then you have to call super. If the function that you override is of type void then it will probably change some state and it would be wise to call super.

It depends on what the function should do.

this is for example some code of my project i am working on.

Header file:

virtual void Tick(float DeltaTime) OVERRIDE;

And this is my tick funcktion in .cpp

void AGAEnemy::Tick(float DeltaTime){

hope this helps.

maikklein - yeah I realize those things, was asking how to actually do it.

Jack Harb - yes it helps alot, I noticed I can override functions without writing OVERRIDE in the header like you did, can you please explain its purpose?

by using OVERRIDE checks to make sure you can indeed override the function. take the below, without override it will not show an error

class mybase
virtual void myfunc();

class myclass : public mybase
virtual void myfunc() override; // this will be ok
virtual void myfunc(int) override; // this will show an error

Gotcha, what is the convention in C++? OVERRIDE or override?

is use OVERRIDE, works for me fine.

Iv always thought it was lowercase, im going to take a look at the ue source now, ill update this and let you know :slight_smile:

override is the actual keyword for VC
OVERRIDE is just a definition pointing to the lowercase keyword, its defined in the UE header 'WindowsPlatform.h" #define OVERRIDE override

Feels like a stupid question, but which should be used then? :slight_smile:

Do the UE programmers use caps?

if minionphil is right, its up to u :wink:

either u want blue or purple highlighting (if u are using the dark vs style :D)

For UE I would use the uppercase,

The reason for this is because the only reason I can think they have defined it as uppercase is for cross platform support.

it wouldn’t make a difference on a windows build of UE, you couldn’t use the uppercase in a none UE project using visual studio unless you also defined it :slight_smile:

sorry if it confused you
Windows C++ Standard: override
UE C++ Framework Standard: OVERRIDE

Makes sense that they defined it for cross platform support. Thanks I guess I’ll use uppercase then.

C++ is a language driven by a standards committee. Every so often, the C++ committee releases a new specification for the language. “C++03” is the informal name given to the language specification released in 2003 and it did not support [FONT=Courier New]override. C++11 was released in 2011 and it does support [FONT=Courier New]override. What this means is that C++03 compliant compilers don’t let you use [FONT=Courier New]override after member function prototypes and C++11 compliant compilers do let you use [FONT=Courier New]override to specify that you want the compiler to check if the function you are trying to override actually exists in a base class. The word [FONT=Courier New]override only has meaning in C++11, and not all compilers implement that standard. I guess they wanted to make the code portable, so on compilers that do support [FONT=Courier New]override, OVERRIDE just means [FONT=Courier New]override; and on older compilers, OVERRIDE could simply define nothing, making OVERRIDE do nothing on older compilers. Most compilers now a days support most of C++11 though, but UE4 has been in development since 2003 (according to Wikipedia), so I’m guessing that’s why they went for OVERRIDE.

Thanks for the info, OVERRIDE seems like the safer choice.

I love the OVERRIDE keyword. IMO the best thing about it is that if if (or we!) change or remove a base class function, you will be get a compile error if you were overriding it, rather than your function silently no longer being called!