Rediger

Del via


Warning C26433

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, the compiler can check the consistency of the interface, and help to spot issues before they manifest themselves at run time.

Notes

This rule isn't applicable to destructors. Destructors have their own virtuality specifics.

The rule doesn't flag functions explicitly marked as final, which is itself a special variety of virtual specifier.

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.

Code analysis name: OVERRIDE_EXPLICITLY

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