我有一個簡單的哈希表的模板,模板類多重定義
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