【发布时间】:2017-01-10 16:54:36
【问题描述】:
我不确定我得到的术语是否正确,但我认为我有一个包含类型和非类型模板参数的类模板,我想仅部分专注于非类型参数:
template<class T, int I> struct A
{
void f();
};
template<class T> void A<T, 1>::f() {}
int main()
{
A<int, 1> a1;
a1.f();
}
使用 Visual C++ 我得到 error C3860: template argument list following class template name must list parameters in the order used in template parameter list 和 error C2976: 'A<T,I>': too few template arguments。
但是,如果我删除类型参数,那么我似乎可以专注于非类型参数:
template<int I> struct B
{
void g();
};
void B<1>::g() {}
int main()
{
B<1> b1;
b1.g();
}
那么我想要的东西是不可能的,还是我没有以正确的方式做到这一点?如果不行,有没有其他办法?
【问题讨论】:
-
见this question。您的模板参数不是类型的事实是一个红鲱鱼。第二个示例有效的原因是因为它是一个完整的专业化。