C++函数模板template
来源:互联网 发布:思迅软件多少钱 编辑:程序博客网 时间:2024/05/22 04:51
一、 函数模板的使用
使用函数模板可以简化 形参个数相同,而类型不同的函数。
template<typename T> //可以用class替换typename
int max(int array[],int len) // int array[len]{ int imax=0; for(int i=0;i<len;i++) { if(array[i]>imax) { imax=array[i];//取得最大值 } } return imax;}float max(float array[],int len) // int array[len]{float imax=0;for(int i=0;i<len;i++){if(array[i]>imax){imax=array[i];//取得最大值}}return imax;}double max(double array[],int len) // int array[len]{double imax=0;for(int i=0;i<len;i++){if(array[i]>imax){imax=array[i];//取得最大值}}return imax;}
代码示范:
template <class S,class ti> S max(S array[],ti len) // int array[len]{S imax=0;for(ti i=0;i<len;i++){if(array[i]>imax){imax=array[i];//取得最大值}}return imax;}
0 0
- C/C++函数模板template
- C++,template,类模板和函数模板
- C++Template学习笔记之函数模板
- 函数模板 Function Template(C++Primer-10)
- Template Functions 模板函数
- Template functions模板函数
- template函数模板
- c++ template 函数模板
- template 函数模板
- C++函数模板template
- C++函数模板template
- 函数模板template
- C++template ;模板学习
- C++template模板
- C++ Template学习笔记之函数模板(1)——函数模板定义
- C++ Template学习笔记之函数模板(7)——重载函数模板
- C++ Template学习笔记之函数模板(1)——函数模板定义
- C++ Template学习笔记之函数模板(7)——重载函数模板
- <数据结构> 实验二 线性表的实验之二
- Android开发书籍推荐
- C++函数重载
- Python 检查数组元素是否存在 类PHP isset()
- Link inside of input tag
- C++函数模板template
- 非递归的二叉搜索树的中序遍历
- date命令的帮助信息
- Ubuntu 下Mysql常用命令
- Change placeholder text without jQuery
- 什么是Spring
- 查询oracle中所有用户信息
- JSONObject用法
- 试图解释一门编程语言