Why Doesn't This Lead to C++'s Most Vexing Parse?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
using std::cout;

class abc
{
  public:
     int i;
     abc(int i) : i(i) {}
};

int main()
{
   abc a(10); // A is initialized like Normal. No Vexing Parse
   std::cout << a.i;
}


Why isn't `a` being parsed as a function? It creates an object of type ABC and prints out 10.
How could it possibly be considered a function declaration? 10 is not a type.

Try this:

1
2
3
4
5
6
7
8
class abc
{
};

int main()
{
   abc a(abc());
}

Last edited on
Is your example parsed as:

`a` is a function that returns abc and takes a function pointer. The function pointer is unnamed, points to a function that takes no arguments and returns abc by value?
Last edited on
Yes. And 'a' can be made a variable with parentheses: abc (a(abc()));
Topic archived. No new replies allowed.