我以为我可以指向一个完全专用的模板函数,但下面的代码没有编译(MSVC2012)
#include <iostream>
#include <string>
#include <unordered_map>
#include <algorithm>
using namespace std;
unsigned long hashing_func(string key)
{
unsigned long hash = 0;
for(int i=0; i<key.size(); i++)
{
hash += (71*hash + key[i]) % 5;
}
return hash;
}
bool key_equal_fn2(string t1, string t2)
{
return t1 == t2;
}
template<class T> bool key_equal_fn(T t1, T t2)
{
return t1 == t2;
}
template <> bool key_equal_fn<string>(string t1, string t2)
{
return !(t1.compare(t2));
}
int main ()
{
unordered_map<string, string>::size_type n …Run Code Online (Sandbox Code Playgroud)