关于 template 源程序分离编译的问题
//a.h
template <class elemType>
class A
{
public:
...
void fun ();
...
};
//a.cpp
include "a.h"
template <class elemType>
void A<elemType>::fun ()
{ ... }
g++ -c a.cpp 或
cl -GX /c a.cpp
如上所示,如在 filename.cpp 中
#include "a.h"
编译
g++ -o filename.exe filename.cpp a.o 或
cl -GX filename.cpp a.obj
fun () 函数均 "undefined reference"
原因偶知道了,但不知怎麽解决
很多书上写使用 export
但 g++ 和 vc 都不支持
请教大家~