虚位以待(AD)
虚位以待(AD)
首页 > 操作系统 > RedHat/Centos > g++模板编译方法

g++模板编译方法
类别:RedHat/Centos   作者:码皇   来源:互联网   点击:

机器版本 linux 2 4 30  ;   g++   3 3 4 g++ 对模板类编译的后,连接时,出现“undefined reference to `int f<long>(long&) ”。文档代码结构a h ---- 定义模板 ifndef __A__H define __A__Htempla
机器版本 linux 2.4.30  ;   g++   3.3.4 g++ 对模板类编译的后,连接时,出现“undefined reference to `int f<long>(long&)'”。文档代码结构a.h ---- 定义模板#ifndef __A__H
#define __A__H
template<typename T>
int f(  T &s);
#endif a.cpp ---- 实现模板#include"a.h"
template<typename T>
int f( T &s)
{
   return 0;
main.cpp ---- 调用模板方法处理#include "a.h"
int main()
{
    long a;
    f<long> (a);
    return 0;
} 这个问题,是g++ “不够完善”引起,可以如下处理1.将a.cpp内容,放到a.h中,去掉a.cpp,编译连接问题解决2.如果还要 a.h 和 a.cpp,则要在main.cpp中,export --- g++ 估计不支持  
相关热词搜索: