Why is this an issue?
For code compliant with C++98 or C++03 standards, declaring overriding virtual functions with the virtual
keyword removes
the need to check the base class to determine whether a function is virtual.
Noncompliant code example
class Base
{
virtual void f();
};
class Derived : public Base
{
void f(); // Noncompliant, implicitly declared "virtual"
};
Compliant solution
class Base
{
virtual void f();
};
class Derived : public Base
{
virtual void f(); // Compliant, explicitly declared "virtual"
};
Resources
- MISRA C++:2008, 10-3-2 - Each overriding virtual function shall be declared with the virtual keyword.
Related rules
- This rule will only trigger with code compliant with C++98 and C++03. For code compliant with C++11 and above see S3471