In C ++ 11, it is possible with the identifier override
:
struct Base { virtual void foo() const { std::cout << "Base::foo!\n"; } }; struct Derived : virtual public Base { virtual void foo() const override {std::cout << "Derived::foo!\n";} };
This allows you to find out at compile time if you are unable to override the method. Here we neglect what the const
method const
:
struct BadDerived : virtual public Base { virtual void foo() override {std::cout << "BadDerived::foo!\n";}
source share