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 |
|
|
|
Function should be marked with override
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.
- 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.
class Shape {
public:
virtual void Draw() = 0;
// ...
};
class Ellipse : public Shape {
public:
void Draw() { // C26433
//...
}
};
C.128: Virtual functions should specify exactly one of virtual, override, or final