[問題] undefined reference to ..

看板Programming作者 (Kornelius)時間18年前 (2007/04/04 03:08), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/4 (看更多)
我在 hashmap.h 內定義 然後在 hashmap.cpp 內實做 主程式寫在 hashtest2.cpp 然後編譯,卻出現這樣的 bug ,一直想不透是什麼問題...搞了好久啊啊啊 Orz 也檢查過,也沒有忘了實做的函數 $ g++ hashtest2.cpp hashmap.cpp -o test /tmp/ccKWvjRU.o: In function `main': hashtest2.cpp:(.text+0x9a): undefined reference to `HashMap<int, int>::HashMap()' hashtest2.cpp:(.text+0xbb): undefined reference to `HashMap<int, int>::add(int, int)' hashtest2.cpp:(.text+0xd6): undefined reference to `HashMap<int, hashtest2.cpp:(.text+0x22b): undefined reference to `HashMap<int, int>::~HashMap()' 不過如果把 hashtest2.cpp 內的 #include "hashmap.h" 加上 #include "hashmap.cpp" 就可以 compile 了..Orz 請問到底是什麼原因呢?會是 Template 的問題嗎? 謝謝. -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.116.170.218 ※ 編輯: kornelius 來自: 59.116.170.218 (04/04 03:09) ※ 編輯: kornelius 來自: 59.116.170.218 (04/04 03:27) ※ 編輯: kornelius 來自: 59.116.170.218 (04/04 03:44)
文章代碼(AID): #164gOx-l (Programming)
文章代碼(AID): #164gOx-l (Programming)