template<typename T>
struct A
{
template<typename U>
A() {}
template<typename U>
static void f() {}
};
int main()
{
A<int>::f<int>(); // ok
auto a = A<int><double>(); // error C2062: type 'double' unexpected
}
The issue is self-evident in the code.
My question is:
How to call a template ctor of a template class?
You cannot directly call a constructor of a class. If you cannot deduce the constructor's template arguments from the call, then that particular constructor is impossible to invoke.
What you can do is create some sort of type wrapper that can be used for zero-overhead deduction:
template <typename T>
struct type_wrapper { };
template<typename T>
struct A
{
template<typename U>
A(type_wrapper<U>) {}
};
int main()
{
auto a = A<int>(type_wrapper<double>{});
}