const class_name obj_name{func()};
Writing down the above, the author tries to adhere to a single initialization syntax (introduced by C ++ 11) to avoid problems caused by annoying analysis and the most unpleasant analysis, in which even experienced programmers fall into the trap by accident. He is trying to incorporate best practice into his brain so that he does not fall into the trap of the parsing issues mentioned, as explained below.
Consider this,
struct X { };
struct Y
{
Y();
Y(int i);
Y(X x);
};
Now you can write this:
Y y(100); // declare an object y of type Y
, . !
:
Y y();
(), , . , . y, y. vexing parse ++.
, (),
Y y(X());
, , X, " ". , . y, ( , X), y. ++.
, , :
Y y1{};
Y y2{100};
Y y3{X{}};
,
Y { function_call() };
const class_name obj_name { func() };
, , , ?
, .