Re: [問題] undefined reference to ..

看板Programming作者 ( )時間18年前 (2007/04/04 12:36), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串3/4 (看更多)
※ 引述《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()' 關於這個你必須要在 .cpp 內的 template 定義式之前加上 export, 不過 g++ 沒有支援 export 這個功能, 所以你必須把 template 定義在 header file 內。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.230.224.23

04/04 21:11, , 1F
謝謝
04/04 21:11, 1F
文章代碼(AID): #164ojGoi (Programming)
文章代碼(AID): #164ojGoi (Programming)