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