In c++11, use curly braces to initialize variables for full application, or you can use curly braces to assign values to variables. An important feature of this initialization when used with built-in type variables is that the compiler will make an error if a list is initialized and the initial value is at risk of losing information.
int _tmain (int argc, _tchar* argv[]) {long double ld = 3.1415926536;int a{ld};int b = {ld};int c (LD); int d = Ld;return 0;}Compiling will get the following error:
(one): Error C2397: Conversion from "long double" to "int" requires narrowing conversion (one): Warning C4244: "Initialization": Converting from "long double" to "int", possibly Losing data (): Error C2397 : Conversion from "long double" to "int" requires a narrowing conversion: Warning C4244: "Initialize": Convert from "long double" to "int", possibly missing data: Warning C4244: "Initialize": from "long" Double "Convert to int", possibly missing data: Warning C4244: "Initialize": Convert from "long double" to "int", possibly losing data
You can see that the compiler rejected the initialization request for A and B.
C + + list initialization