【发布时间】:2017-05-05 15:37:54
【问题描述】:
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
}
问题在代码中不言而喻。
我的问题是:
如何调用模板类的模板ctor?
【问题讨论】:
-
明显的绕过是
A<int>::A<double>();,但这是非法的语法。因此,正如 Vittorio 在他的回答中提到的那样,如果没有某种包装器,这是不可能的。
标签: c++ templates syntax constructor type-deduction