C++11 added override
to ensure that member functions you write that you intend to override base-class virtual functions actually do (or won\'t compile).
There are two things you can do.
First, Clang 3.5 and higher have a -Winconsistent-missing-override
warning (triggered by -Wall
). This does not quite work for your example, but only if you would add a void foo() override {}
to class B
and not in class C
. What you actually want is -Wmissing-override
, to locate all missing override
, not just the inconsistently missing ones. That is currently not provided, but you might complain on the Clang mailinglist and they might add it.
Second, you use Howard Hinnant's trick to temporarily add final
to the base class member function and recompile. The compiler will then locate all further derived classes that attempt to override the virtual
base member function. You can then fix the missing ones. It's a bit more work and requires frequent rechecking when your class hierarchy expands.