+ 2

Is there any difference? If not, then why is this syntax needed: int y {2} ?

https://code.sololearn.com/cpmfwpZ8TZmN/?ref=app

16th Sep 2019, 8:51 PM
UraL
5 ответов
+ 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
16th Sep 2019, 9:56 PM
Shadow
Shadow - avatar
+ 3
Shadow very big and bold thanx
16th Sep 2019, 10:31 PM
UraL
+ 2
~ swim ~ Why were such difficulties introduced in C ++? He's getting too complicated
17th Sep 2019, 10:14 AM
UraL