I was reading an SO post where one user made the following comment:
Also note that
ArrTest<int> ar();
uses most vexing parse.
But another user said the opposite:
ArrTest<int> ar();
is not the "most vexing parse". It's just a function declaration. It's certainly vexing for beginners, but, as the page you linked to indicates, the "most vexing parse" is more convoluted.
The code example from that post is given below for reference:
template <class ItemType>
class ArrTest {
public:
ArrTest();
private:
ItemType* info;
};
//some other code here
int main() {
ArrTest<int> ar(); //DOES THIS USE THE MOST VEXING PARSE?
return 0;
}
My first question is that is the concept of "most vexing parse" formally defined by the C++ standard. My second question is that does the statement ArrTest<int> ar();
uses most vexing parse. That is, which of the above two quoted comments is technically correct?
This also seem to suggest that MyObject object();
is most vexing parse.
As the author of the second quote in the question, yes, it's a bit pedantic, but applying the term "most vexing parse" to
int f();
, which every C++ programmer will recognize as a function declaration, is misleading.When you see
int f();
you should thing "function declaration". And when you need to write a declaration of a function that takes no arguments and returnsint
you should think ofint f();
. That's how you do it. On the other hand, when you see something likeTimeKeeper time_keeper(Timer());
, maybe you should think "function declaration", because that's what it is, but if you want to declare a function that takes an argument of typeTimer
and returnsTimeKeeper
you should not think ofTimeKeeper time_keeper(Timer());
. That way lies madness. Or, at best, vexation."Most Vexing Parse" is useful as a label that says "you've done something confusing here".
int f();
is not confusing;TimeKeeper time_keeper(Timer());
is. On the other hand, if "most vexing parse" is applied to any application of that disambiguation rule, then you need a term for "most vexing parse that's useful and necessary" and another for "most vexing parse that you should not have written". Simpler is better.