3

I have a base class Base, a somewhat more specialized class SpecializedBase derived from Base, and subclasses of the latter such as Derived.

I implement a virtual function in SpecialisedBase which is pure virtual in Base. How to be sure that this function is not overloaded in Derived?

brasofilo
  • 25,496
  • 15
  • 91
  • 179
galinette
  • 8,896
  • 2
  • 36
  • 87

1 Answers1

6

yes, if you can use C++11, you can write your class like

    struct derived {
        virtual void f() final;
    };
CS Pei
  • 10,869
  • 1
  • 27
  • 46
  • 1
    but wait, there's more: you can even put `final` after the class name and prevent the entire class from being inherited from. – TemplateRex Sep 24 '13 at 14:35