Both virtual and override?

I see in the coding style guide:

“Use the virtual and override keywords when declaring an overriding method. When declaring a virtual function in a derived class, that overrides a virtual function in the parent class, you must use both the virtual and the override keywords.”

Anyone know why both are required by the style? virtual is redundant when override is specified, so it just adds to the verbosity.

Those specifications are in general for engine contributions.

For example when submitting a PR I follow Epic 100%, when doing external code I use auto-formatting scripts with whatever style I want to use in VisualStudio.

Yes - I understand that. If/when I submit anything of course I would follow the style.

Just trying to understand the rationale since it’s just more noise when trying to navigate/parse/understand the code.

Thought I might be missing a good reason - like a compiler that doesn’t support C++11 properly. :smiley:

The good reason is that it becomes more obvious what they’re doing. Half of the unreal code style is about writing as verbose as you can to help other readers.

Thanks Zeblote. I 100% agree that code should be written for humans. I don’t agree that verbosity (always) implies clarity.

The virtual keyword in this case doesn’t add any information or make anything easier to understand. A function declared using override is virtual so it’s completely redundant.

So I don’t understand how this makes it more obvious what they’re doing.

But we can disagree :slight_smile: Just wondered if I was missing something.

I found this post via google search, had been wondering the same thing: Why does UE coding standard explicitly say:

"When declaring a virtual function in a derived class that overrides a virtual function in the parent class, you must use both the virtual and the override keywords

especially when the ISO C++ Core Guidelines (edited by Bjarne Stroustroup and Herb Sutter) say the opposite (and IMO with some good reasoning):

This appears to have been added to those guidelines almost nine years ago: virtual functions should specify exactly one of `virtual`, `override`, or `final` · Issue #423 · isocpp/CppCoreGuidelines · GitHub

If the UE coding standards predate that, perhaps it’s time to relax or reverse this mandated use of both virtual and override.