San*_*eep 1 c++ templates template-specialization
我试图了解常量模板专业化.考虑以下模板功能和一个专业化:
enum class NodeType
{A, B, C};
template<NodeType>
bool afunc()
{
cout<<"calling generic"<<endl;
}
template<>
bool afunc<NodeType::A>()
{
cout<<"calling specific"<<endl;
}
Run Code Online (Sandbox Code Playgroud)
我能够调用专门的实例,如下所示:
const NodeType x = NodeType::A;
afunc<x>();
Run Code Online (Sandbox Code Playgroud)
但是,如果我删除const然后编译器抱怨模板/参数推断失败.为什么const必要?