+ 2
Is there any difference? If not, then why is this syntax needed: int y {2} ?
5 Answers
+ 6
With C++11, the so-called feature "uniform initialization" was introduced. It's meant as a consistant syntax for initializing objects, be it in-built types like int, aggregates, or containers. The only real difference is that if the type of the variable to be initialized and the type of the value don't align, the compiler won't attempt an implicit conversion first, but will throw an error instead immediately.
For example:
int a = 9.42; // okay, a = 9
int b { 9.42 }; // error
Here are some reference articles you should see for yourself:
https://mbevin.wordpress.com/2012/11/16/uniform-initialization/
https://en.cppreference.com/w/cpp/language/aggregate_initialization
https://softwareengineering.stackexchange.com/questions/133688/is-c11-uniform-initialization-a-replacement-for-the-old-style-syntax
+ 3
Shadow very big and bold thanx
+ 2
~ swim ~ Why were such difficulties introduced in C ++? He's getting too complicated