diff --git a/README.md b/README.md index b80e20d..131a86f 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ C++11 includes the following new language features: - [delegating constructors](#delegating-constructors) - [user-defined literals](#user-defined-literals) - [explicit virtual overrides](#explicit-virtual-overrides) +- [final specifier](#final-specifier) - [default functions](#default-functions) - [deleted functions](#deleted-functions) - [range-based for loops](#range-based-for-loops) @@ -793,6 +794,33 @@ struct B : A { }; ``` +### Final specifier +Specifies that a virtual function cannot be overridden in a derived class or that a class cannot be inherited from. +```c++ +struct A { + virtual void foo(); +}; + +struct B : A { + virtual void foo() final; +}; + +struct C : B { + virtual void foo(); // error -- declaration of 'foo' overrides a 'final' function +}; +``` + +Class cannot be inherited from. +```c++ +struct A final { + +}; + +struct B : A { // error -- base 'A' is marked 'final' + +}; +``` + ### Default functions A more elegant, efficient way to provide a default implementation of a function, such as a constructor. ```c++