Skip to content

Latest commit

 

History

History
46 lines (35 loc) · 1.7 KB

c26433.md

File metadata and controls

46 lines (35 loc) · 1.7 KB
description title keywords ms.date ms.topic f1_keywords helpviewer_keywords dev_langs
Learn more about: C26433 OVERRIDE_EXPLICITLY
C26433
C26433
01/18/2017
reference
C26433
C26433
C++

C26433 OVERRIDE_EXPLICITLY

Function should be marked with override

C++ Core Guidelines

C.128: Virtual functions should specify exactly one of virtual, override, or final

It's not required by the compiler to clearly state that a virtual function overrides its base. Not specifying override can cause subtle issues during maintenance if the virtual specification ever changes in the class hierarchy. It also lowers readability and makes an interface's polymorphic behavior less obvious. If a function is clearly marked as override, it enables the compiler to check consistency of the interface and help to spot issues before they manifest themselves at run time.

Notes

  1. This rule isn't applicable to destructors. Destructors have their own virtuality specifics.
  2. The rule doesn't flag functions explicitly marked as final, which is itself a special variety of virtual specifier.
  3. Warnings show up on function definitions, not declarations. It may be confusing, since definitions don't have virtual specifiers, but the warning is still correct.

Example: Implicit overriding

class Shape {
public:
    virtual void Draw() = 0;
    // ...
};

class Ellipse : public Shape {
public:
    void Draw() { // C26433
        //...
    }
};

See also

C.128: Virtual functions should specify exactly one of virtual, override, or final