Re: [問題] undefined reference to ..
※ 引述《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
討論串 (同標題文章)
Programming 近期熱門文章
PTT數位生活區 即時熱門文章