Updated
I have gone through links (such as When to use the brace-enclosed initializer?) on when should I use use {}
brace initialization, but information is not given on when we should use parenthesis ( )
vs. initializer { }
syntax to initialize objects in C++11/14? What standard practices suggest to use ()
over {}
?
In rare cases, such as vector<int> v(10,20);
or auto v = vector<int>(10,20);
, the result is a std::vector
with 10 elements. If we uses braces, the result is a std::vector
with 2 elements. But it depends on the caller use case: either he/she want to allocate vector of 10 elements or 2 elements?