How does this declaration invoke the Most Vexing Parse?

后端 未结 2 1548
有刺的猬
有刺的猬 2020-12-07 01:03

Consider the following program:

#include 

struct A {};

int main(int argc, char** argv) {
    A a(std::fstream(argv[1]));
}

2条回答
  •  既然无缘
    2020-12-07 02:01

    The parens are superfluous. All of the following are the declarations:

    T a;
    T (a);
    T ((a));
    T (((a))));
    

    so are these:

    T a[1];
    T (a[1]);
    T ((a[1]));
    T (((a[1]))));
    

    So is this:

     A a(std::fstream(argv[1]));
    

    which is same as:

     A a(std::fstream argv[1]);
    

    which is same as:

     A a(std::fstream *argv);
    

    Hope that helps.

提交回复
热议问题