It's because C++ templates can be specialized.
That means that just because there's a main definition:
template<typename T>
class Foo
{
Foo(T x) { }
};
and clearly int
will be accepted by Foo<int>(int)
, it's completely possible that there's also a specialized definition
template<>
class Foo<Foobar>
{
Foo(int x) { }
};
which also accepts an int
parameter.
Add user-defined type conversions to the mix, and you see that it just isn't possible to figure out the class's type parameters from function arguments.
And in fact, inference of type parameters for constructors IS allowed. But not inference of the class template parameters. For example, allowing implicit upcast when constructing a smart pointer:
template<typename T>
class a_smart_ptr
{
template<typename TOther>
a_smart_ptr(TOther* p) { }
};