Explicitly overriding virtual methods with 'override' specifier

Question | Dec 31, 2016 | nextptr 

C++11 standard introduced a method specifier - override - to explicitly tell the compiler that the specified method is overriding a method in a base class. Explicitly marking a method 'override' makes the intention clear, and helps catch the defects at compile time.

Below is an example polymorphic class hierarchy with virtual methods. To detect any programming errors at compile time the methods are marked override in derived classes.

class A {
public:
  virtual bool Foo(int i=0) { return true; }
  virtual void Bar(int i, int j) { }
  void Stick() {}
};

class B : public A {
public:
   virtual bool Foo() override { return false; }
   virtual void Bar(int i, int j) override {}
   virtual void Bar(int i) override {}
   virtual void Glue() {}
   virtual void Glue() const {}
};

class C : public B {
public:
  virtual void Glue() const override {}
  virtual void Stick() override {}
};

You have to check all those methods below (from above code) that would fail to compile: