Search code examples
c++syntaxdeclarationmost-vexing-parse

I do not understand why this compiles


I'm certainly missing something, but I do not understand why this compiles (with both g++ & clang++):

struct A
{
};
struct B
{
};

int main()
{
  A a(B);
}

First of all, B is a type... not a value. How should I interpret this code?


Solution

  • It's interpreted as the declaration of a function named a, which takes one argument of type B and returns A.