c++ - Most vexing parse: why doesn't A a(()); work? -
among many things stack overflow has taught me known "most vexing parse", classically demonstrated line such as
a a(b()); //declares function while this, most, intuitively appears declaration of object a of type a, taking temporary b object constructor parameter, it's declaration of function a returning a, taking pointer function returns b , takes no parameters. line
a a(); //declares function also falls under same category, since instead of object, declares function. now, in first case, usual workaround issue add together set of brackets/parenthesis around b(), compiler interpret declaration of object
a a((b())); //declares object however, in sec case, doing same leads compile error
a a(()); //compile error my question is, why? yes i'm aware right 'workaround' alter a a;, i'm curious know () compiler in first illustration doesn't work when reapplying in sec example. a a((b())); workaround specific exception written standard?
there no enlightened answer, it's because it's not defined valid syntax c++ language... so, definition of language.
if have look within valid. example:
((0));//compiles to larn more how languages defined, , how compilers work, should larn formal language theory or more context free grammars (cfg) , related material finite state machines. if interested in though wikipedia pages won't enough, you'll have book.
c++
No comments:
Post a Comment