出错代码如下:
template<int count>
inline size_t StringHashFamily<int>::hash(const string& x, int which)const
{
const int multipliers = MULTIPLERS[which];
size_t hashval = 0;
for (auto& ch : x) { hashval = multipliers * hashval + ch; }
return hashval;
}
出错原因如下:
StringHashFamily<int>:://该模板不能实例化,因为模板参数不是类型
应修改如下:
StringHashFamily<count>:://该模板实例化就是具体类型了
关键在于模板参数是非类型模板参数。