Avatar ·

Advantages of list initialization (curly braces) in C++11 and later

Hello everyone! I started learning C++11 and came across a new feature — initialization using curly braces (list initialization). For example: ```cpp std::vector v = {1, 2, 3}; int x{0}; ``` It seems to work, but I don't understand why it's needed when there's the good old initialization with parentheses or the assignment operator. It seems to me like just syntactic sugar. But I've heard that curly braces solve some problems. For example, I read that they prevent narrowing conversions. But what is that? And what are the other advantages? I have a specific example that confuses me: ```cpp int a = 3.14; // a == 3, just loses the fractional part int b(3.14); // same thing int c{3.14}; // Compilation error! Why? ``` I underst