如果我有像
这样的代码struct Foo
{
template<class T>
Foo(T arg) { }
};
会阻止T
const
,volatile
或引用吗?
同样,如果我有
struct Bar
{
template<class T>
Bar(T const volatile &arg) { }
};
这是否意味着T
永远不会是const
,volatile
或参考?
基本上,这是否意味着必须推断构造函数模板参数,即不能将其指定为推断值以外的任何其他内容?
答案 0 :(得分:3)
是的,在调用构造函数模板时,无法显式指定模板参数。
因为你从不直接调用它,但总是通过强制转换或声明隐式调用它。
只有在明确专门化或实例化时才能指定它们。这不是很有用,但可能
// explicit instantiation
template Bar::Bar<const int>(const int);