mirror of
https://github.com/AnthonyCalandra/modern-cpp-features.git
synced 2025-12-18 10:34:35 +03:00
Add section on non-static data member initializers
Since C++11, N2756 specifies that you can initialize a non-static member on its declaration.
This commit is contained in:
18
README.md
18
README.md
@@ -64,6 +64,7 @@ C++11 includes the following new language features:
|
|||||||
- [converting constructors](#converting-constructors)
|
- [converting constructors](#converting-constructors)
|
||||||
- [explicit conversion functions](#explicit-conversion-functions)
|
- [explicit conversion functions](#explicit-conversion-functions)
|
||||||
- [inline-namespaces](#inline-namespaces)
|
- [inline-namespaces](#inline-namespaces)
|
||||||
|
- [non-static data member initializers](#non-static-data-member-initializers)
|
||||||
|
|
||||||
C++11 includes the following new library features:
|
C++11 includes the following new library features:
|
||||||
- [std::move](#stdmove)
|
- [std::move](#stdmove)
|
||||||
@@ -1015,6 +1016,23 @@ int oldVersion {Program::Version1::getVersion()}; // Uses getVersion() from Vers
|
|||||||
bool firstVersion {Program::isFirstVersion()}; // Does not compile when Version2 is added
|
bool firstVersion {Program::isFirstVersion()}; // Does not compile when Version2 is added
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Non-static data member initializers
|
||||||
|
Allows non-static data members to be initialized where they are declared, potentially cleaning up constructors of default initializations.
|
||||||
|
|
||||||
|
```c++
|
||||||
|
// Default initialization prior to C++11
|
||||||
|
class Human {
|
||||||
|
Human() : age(0) {}
|
||||||
|
private:
|
||||||
|
unsigned age;
|
||||||
|
};
|
||||||
|
// Default initialization on C++11
|
||||||
|
class Human {
|
||||||
|
private:
|
||||||
|
unsigned age = 0;
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
## C++11 Library Features
|
## C++11 Library Features
|
||||||
|
|
||||||
### std::move
|
### std::move
|
||||||
|
|||||||
Reference in New Issue
Block a user