Re: [問題] undefined reference to ..

看板Programming作者 (Kornelius)時間18年前 (2007/04/04 03:51), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/4 (看更多)
http://tinyurl.com/396nxb 我在這頁找到 G++ requires template header in the same file as implementation. In practice it means implementation inside .h file. 是這樣的原因嗎? ※ 引述《kornelius (Kornelius)》之銘言: : 我在 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
文章代碼(AID): #164h0hYt (Programming)
文章代碼(AID): #164h0hYt (Programming)