+ 1

In C++11 and higher, should types like int, string, double, etc. be initialized with braces?

Before C++11, the standard way to initialize fundamental types was: int i = 0; string s = "s!"; if I'm not mistaken (which I probably am, considering that this is C++ I'm talking about). Anyway, now, you can do: int i{0}; string s{"s!"}; So should I use the second type instead of the first?

17th Sep 2018, 4:24 AM
LunarCoffee
LunarCoffee - avatar
1 Resposta
+ 1
Yes you should use the second and here is a thorough explanation as to why https://www.learncpp.com/cpp-tutorial/2-1-fundamental-variable-definition-initialization-and-assignment/
17th Sep 2018, 6:36 AM
Learn