作者kornelius (Kornelius)
站内Programming
标题[问题] undefined reference to ..
时间Wed Apr 4 03:08:42 2007
我在 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)