Merge pull request #11 from orabaev/master

Add final specifier
This commit is contained in:
Anthony Calandra
2017-01-03 15:27:13 -05:00
committed by GitHub

View File

@@ -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++