This statement:
Foo(x);
is not a function call, or a constructor call. It's just a declaration, that says x
is of type Foo
. The parentheses are optional around the declarator x
, so it's equivalent to:
Foo x;
This of course gives an error, since you already have a std::string
named x
, and you can't give the same name to multiple entities in the same scope.
Note that the expression:
Foo(x)
is different than the statement above (with the ;
). This expression can mean different things depending on the context it is used in.
For example, this code:
Foo foo = Foo(x);
is perfectly fine. This does copy initialization of a variable named foo
, from the expression Foo(x)
, which is a temporary Foo
constructed from the argument x
. (It's not particularly important here, but from c++17, there's no temporary on the right hand side; the object just gets constructed in place).