Is C++11 uniform initialization a replacement for the old style syntax? -- Programmers.StackExchange
Here is a question from Programmer's StackExchange (tags [c++] and [c++11]) which most C++ developers, whatever their level, will ask as soon as they are introduced to the new Uniform Initialization syntax:
Is it recommended now to use uniform initialization in all cases? What should the general approach be for this new feature as far as coding style goes and general usage? What are some reasons to not use it?
The accepted answer clearly provides very good reasons to use this new syntax as much as possible (if your compiler supports it already): minimizing redundant typenames and avoiding the Most Vexing Parse. It also points some reasons to not use this syntax, in particular in case you're trying to call a standard container constructor.
There is one other reason not to:
std::vector<int> v{100};What does this do? It could create a
vector<int>
with one hundred default-constructed items. Or it could create avector<int>
with one item whose value is100
. ... In actuality, it does the latter.
Read the full QA.