我有一个简单的哈希表的模板,模板类多重定义
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.h) strSimpleHash仅被定义在hashtable.h
有没有出路? PS抱歉我写错了。英语不是我的母语
您是否在模板特化之前或之后定义了strSimpleHash?它需要在之前。 – Dave 2013-04-07 18:42:24
我将它定义模板和模板特 – 2013-04-07 18:44:55
之前,请表现出更多,代码,尤其是在其中定义'strSimpleHash',更完整的答案的一部分。 – Synxis 2013-04-07 18:46:26