Consider the following code:
struct Foo { }; struct Bar { explicit Bar(const Foo&) { } }; int main() { Foo foo; Bar bar(foo);
Why do I need a bracket around the temporary version? What ambiguity do they solve?
My hunch is this: I think the compiler sees Bar(foo) as a declaration for a function, but I'm not sure why this will be so, since foo (instance) is not a type. Consequently, the brackets cause the above expression to be considered as an expression, and not as a foreground declaration.
source share