[問題] undefined reference to ..
我在 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)
討論串 (同標題文章)
以下文章回應了本文 (最舊先):
完整討論串 (本文為第 1 之 4 篇):
Programming 近期熱門文章
PTT數位生活區 即時熱門文章