我有一个简单的哈希表模板,
template <class K, class V, long H(K)>
class HashTableAbs{/* .... */}
//where K is key type, V is value type, H gives hash code for K value
和简单的继承者类
template <class K, class V, long H(K)>
class HashTable:public HashTableAbs<K, V, H> {};
我想用我的默认哈希函数专门为字符串模板
template <class V>
class HashTable<std::string, V, strSimpleHash>:public HashTableAbs<std::string, V, strSimpleHash> {};
//where strSimpleHash is long strSimpleHash(std::string)
但是当我试图编译这个编译器时,写这个
test.o: In function `strSimpleHash(std::string)':
test.cpp:(.text+0x0): multiple definition of `strSimpleHash(std::string)'
/tmp/main-i7yPhc.o:main.cc:(.text+0x0): first defined here
clang: error: linker command failed with exit code 1 (use -v to see invocation)
(测试包括定义了 HashTable 的 hashtable.h) strSimpleHash 仅在 hashtable.h 中定义
有出路吗?PS对不起我的写作错误。非我母语的英语