Most complier fail to implement the compliing mechnisam of function template-separation model, include g++,v s2008. Follow is my test code.
in "separation_model.h"
#if !defined(SEPARATION_MODEL)
#define SEPARATION_MODEL
template <class T>
T _max(T pf,T ps);
#endifin "separation_model.cpp"
#include "separation_model"
export template <class T>
T _max(T pf, T ps) ...{
if (pf > ps) return pf;
else return ps;
}in test code "separetion_test.cpp"
#include "separation_model.h"
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
...{
cout << _max(10, 20) << endl;
system("pause");
return 0;
}
本文介绍了一个使用模板分离模型实现最大值函数的例子。该方法通过将模板声明与定义分离来提高代码复用性和编译效率。文章包含完整的源代码示例,展示了如何在不同文件中分别进行模板声明和定义。
1800

被折叠的 条评论
为什么被折叠?



