Does anyone know why the third way of invoking func doesn't work.
template <typename T>
struct Foo
{
Foo(T t) { }
};
template <typename T>
void func(const Foo<T>& f)
{ }
int main(int argc, char *argv[])
{
func<int>(42); // works
func(Foo<int>{42}); // explicit braced initialization works
func({42}); // implicit braced initialization, doesn't work
return 0;
}
Ideally, {42} could either be a std::initializer list or it could be some type which can take an int value. Shouldn't the compiler be able to look at what is being called, what it expects and whether such a conversion is possible.
Aucun commentaire:
Enregistrer un commentaire