Thursday, August 7, 2014

The `override` Keyword in C++11

Since C++11 has been released, a lot of new things are added in newer versions of working draft (available at http://www.open-std.org/jtc1/sc22/wg21/). Recently I've come to know about the `override` keyword (which is not actually a `keyword` but an identifier with a special meaning).

A very good description with code example is given in this link below,
http://stackoverflow.com/questions/18198314/override-keyword-in-c

Key points are,
  1. Works with virtual functions.
  2. The identifier `override` makes sure that the base class has the same function signature if you write override specifier after some virtual function in derived class.
  3. Quoting working draft C++11 N3242 (published on 28-Feb-2011),
    If a virtual function is marked with the virt-specifier override and does not override a member function of a base class, the program is ill-formed.

No comments :

Post a Comment