Which Lines Are Rejected

Which lines does a conforming compiler reject?

struct A { virtual void run(); };            // line 1
struct B : A { void run() final; };          // line 2
struct C final : B { };                      // line 3
struct D : B { void run(); };                // line 4
struct E : C { };                            // line 5
A

Line 3 only. A class may not be marked final unless every virtual function it inherits is also final.

B

Lines 4 and 5

C

Line 4 only. Deriving from a final class is allowed as long as the derived class overrides nothing.

D

Line 5 only. D::run lacks the override keyword, so it hides B::run rather than overriding it, and final is not engaged.