模板编译模式问题
我想利用“分离模式”来编译我下面的模板程序(三个文件:head.h,main.cpp,other.cpp):
---------------------------------------------------
head.h:
#include <iostream>
using namespace std;
template <class T> //模板声明
void test(T a);
---------------------------------------------------
other.cpp:
#include "head.h"
export template <class T> //模板定义
void test(T a){
cout << a << endl;
}
---------------------------------------------------
main.cpp:
#include "head.h"
int main(int argc, char **argv){
test(9); //模板实例化
return 0;
}
---------------------------------------------------
然后,我首先在windows下利用visual studio.net进行编译---->失败。
我好像听说过vc并不支持模板的“分离模式”编译,但是gcc应该支持,所以我在linux中重新编译上面的程序:
g++ main.cpp other.cpp -o a.o
结果还是失败。
难道gcc也不支持“分离模式”编译?或者是在编译时还需要使用其他选项?
望高手指教,谢谢。