我在模板元编程的初学者试图实现代相似,但略有不同的代码多个版本:为什么我的程序不能工作,当我尝试部分专门化功能模板?
#include <iostream>
enum Type
{
a1,
a2
};
enum Style
{
b1,
b2
};
template<Type,Style>
void doSomething();
{
std::cout<<" some rubbish\n";
};
完全专业化运作良好:
template<>
void doSomething<a1,b2>()
{
std::cout<<" this is my template parameters one :" <<a1<< " and two:"<<b2<<std::endl;
}
int main(int argc, char* argv[])
{
doSomething<a1,b1>();
doSomething<a1,b2>();
return 0;
}
:一些垃圾
:这是我的模板参数之一:0和2:1
但部分专业化像bel流失败:
template<Style Some>
void doSomething<a1,Some>()
{
// here I want to use sub-template on some: e.g do_other<Some>
}
错误: 错误C2768:“DoSomething的”:非法使用显式模板参数
(通用模板的身体在这种情况下评论,但它并没有任何区别)
这种专业化在所有样本中都是部分专业化的,但对我无效。这让我很困惑。
非常感谢您的任何建议
事实是,你不能做功能模板的部分专业化。看到这个问题:[我可以使用部分模板专业化(非成员)功能?](http://stackoverflow.com/questions/1961659/can-i-use-partial-template-specialization-for-a非成员函数) –