why is this instantiation of a template class with a temporaryanonymous object a vexing parse?

This declaration:

Owner<Foo> owner( Foo() );

is indeed a vexing parse. It declares owner as a function that returns an Owner<Foo>, and which has a single parameter. That single parameter Foo() is itself interpreted as a function that returns a Foo and has no parameters.

The simplest way to fix this is by using braces instead of parentheses:

Owner<Foo> owner{ Foo{} };

and now there’s no ambiguity, and no need for any named variables of type Foo.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top