【发布时间】:2019-05-03 10:28:18
【问题描述】:
我很难理解在以下情况下如何进行扣减:
template<class Category, Category code>
struct AImpl
{ };
template<class Category, Category code>
struct AHelper
{
using type = AImpl<Category, code>;
};
template<class Category, Category code>
using A = typename AHelper<Category, code>::type;
template<int code>
void doSomething(A<int, code> object)
{
}
以下是测试代码:
A<int, 5> a1;
doSomething(a1); // This does not compile
doSomething<5>(a1); // This compiles
为什么在这种情况下不推导出a1?
如果您改用以下方式修改 A:
template<class Category, Category code>
struct A
{ };
两者都有效。有谁知道为什么?
【问题讨论】:
标签: c++ c++11 templates template-meta-programming template-argument-deduction