模板编译模式问题

OOPhaisky OOPhaisky 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我想利用“分离模式”来编译我下面的模板程序(三个文件: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也不支持“分离模式”编译?或者是在编译时还需要使用其他选项?

望高手指教,谢谢。
...全文

相关推荐

评论 24
收藏 已收藏
分享
返回顶部
OOPhaisky
C++ 语言 65,214 成员 250,514 内容