c++ - Most vexing parse C++11 -
I y y {X {}}; and in fact what this line does is brief description of what it is most concerned with the most troubled parse:
#include & lt ; Iostream & gt; Straight X {X () {std :: cout & lt; & Lt; "X"; }}; Structure Y [Y (Const X and X) {std :: cout & lt; & Lt; "Y"; } Zero F () {std :: cout & lt; & Lt; "F"; }}; Int main () {y y {X {}}; Y.f ();
what exactly does this row
makes this a temporary X , calling it the default constructor and starting the value, and then to start the y variable, Const X conversion constructor.
Where is the most troubled pars
If you have it used to do old-school initialization syntax
y y X ()); Then the so-called "most troubled parse" will interpret it as a function, as a function, declaration: a code whose name is y , Return type with Y and a single parameter, whose type is (back indicator) function X .
You can add additional brackets so that it can not be interpreted as a function declaration:
y y ((x () ()); < / Code> Or, since C ++ 11, you can use brace-initialization, as is your example.
Comments
Post a Comment