История изменений
Исправление ovk48, (текущая версия) :
Читните первоисточник, т.е. страусятину.
Stroustroup, The C++ Programming Language, 4ed.
Initialization using {} , list initialization, does not allow narrowing
char c4 {24}; // OK: 24 can be represented exactly as a char char c5 {264}; // error (assuming 8-bit chars): 264 cannot be represented as a char int x4 {2.0}; // error : no double to int value conversion
...
There is no advantage to using {} initialization, and one trap, when using auto to get the type determined by the initializer. The trap is that if the initializer is a {} -list, we may not want its type deduced (§6.3.6.2). For example:
So prefer = when using auto .auto z1 {99}; // z1 is an initializer_list<int> auto z2 = 99; // z2 is an int
...
The empty initializer list, {} , is used to indicate that a default value is desired. For example:
int x4 {}; // x4 becomes 0 double d4 {}; // d4 becomes 0.0 char∗ p {}; // p becomes nullptr vector<int> v4{}; // v4 becomes the empty vector string s4 {}; // s4 becomes ""
Исправление ovk48, :
Читните первоисточник, т.е. страусятину.
Stroustroup, The C++ Programming Language, 4ed.
Initialization using {} , list initialization, does not allow narrowing
...
There is no advantage to using {} initialization, and one trap, when using auto to get the type determined by the initializer. The trap is that if the initializer is a {} -list, we may not want its type deduced (§6.3.6.2). For example:
So prefer = when using auto .auto z1 {99}; // z1 is an initializer_list<int> auto z2 = 99; // z2 is an int
...
The empty initializer list, {} , is used to indicate that a default value is desired. For example:
int x4 {}; // x4 becomes 0 double d4 {}; // d4 becomes 0.0 char∗ p {}; // p becomes nullptr vector<int> v4{}; // v4 becomes the empty vector string s4 {}; // s4 becomes ""
Исходная версия ovk48, :
Stroustroup, The C++ Programming Language, 4ed.
Initialization using {} , list initialization, does not allow narrowing
...
There is no advantage to using {} initialization, and one trap, when using auto to get the type determined by the initializer. The trap is that if the initializer is a {} -list, we may not want its type deduced (§6.3.6.2). For example:
So prefer = when using auto .auto z1 {99}; // z1 is an initializer_list<int> auto z2 = 99; // z2 is an int
...
The empty initializer list, {} , is used to indicate that a default value is desired. For example:
int x4 {}; // x4 becomes 0 double d4 {}; // d4 becomes 0.0 char∗ p {}; // p becomes nullptr vector<int> v4{}; // v4 becomes the empty vector string s4 {}; // s4 becomes ""