自定义控件内写的函数模板,在空间外定义时该怎么写?请高手赐教
自定义控件内写的函数模板,在空间外定义时该如何写?请高手赐教
//cpph.h
namespace new_space{
template<class T>T sub(T a,T b){
return a+b;
}
}
//cpps.cpp
//cppm.cpp
#include<iostream>
#include<iomanip>
#include"cpph.h"
using namespace std;
using namepace new_space;
int main(int arg,char *vga[]){
cout<<"两数值相加求和结果是:"<<sub(3,4)<<endl;
return 0;
}
在该实例中如果将cpph.h中的函数定义移到cpps.cpp文件中实现,该如何编写?请高手赐教,谢谢!
------解决方案--------------------
没有方法,标准不支持分离编译。
------解决方案--------------------
又想了一下,如果你确定的知道 sub 的实例化类型,可以通过显示实例化解决,不过很麻烦。
//cpph.h
namespace new_space{
template<class T>T sub(T a,T b){
return a+b;
}
}
//cpps.cpp
//cppm.cpp
#include<iostream>
#include<iomanip>
#include"cpph.h"
using namespace std;
using namepace new_space;
int main(int arg,char *vga[]){
cout<<"两数值相加求和结果是:"<<sub(3,4)<<endl;
return 0;
}
在该实例中如果将cpph.h中的函数定义移到cpps.cpp文件中实现,该如何编写?请高手赐教,谢谢!
------解决方案--------------------
没有方法,标准不支持分离编译。
------解决方案--------------------
又想了一下,如果你确定的知道 sub 的实例化类型,可以通过显示实例化解决,不过很麻烦。