c++中的函数模版
来源:互联网 发布:百度 程序员 签字费 编辑:程序博客网 时间:2024/06/07 13:02
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
/**
template<typename T>函数模板(T:支持泛型编程)
returnType functionName(T para1,...)
*/
template<typename T>
T maxValue(T x,T y)
{
return x>y?x:y;
}
int main()
{
cout<<"Int:max is "<<maxValue(255,256)<<endl;
cout<<"Long:max is "<<maxValue(65535L,65536L)<<endl;
cout<<"Float:max is "<<maxValue(32767.0f,32768.0f)<<endl;
cout<<"Double:max is "<<maxValue(pow(2,31),pow(2,32))<<endl;
return 0;
}
#include<string>
#include<cmath>
using namespace std;
/**
template<typename T>函数模板(T:支持泛型编程)
returnType functionName(T para1,...)
*/
template<typename T>
T maxValue(T x,T y)
{
return x>y?x:y;
}
int main()
{
cout<<"Int:max is "<<maxValue(255,256)<<endl;
cout<<"Long:max is "<<maxValue(65535L,65536L)<<endl;
cout<<"Float:max is "<<maxValue(32767.0f,32768.0f)<<endl;
cout<<"Double:max is "<<maxValue(pow(2,31),pow(2,32))<<endl;
return 0;
}
0 0
- 函数模版中的引用
- c++中的函数模版
- C++template--函数模版
- 【c++】函数模版
- 【C++】认识模版函数
- C++——模版:函数模版
- 简单理解 C ++ 中的模版
- 8. Smarty3:模版中的内置函数
- C语言宏实现模版函数
- C++ 之函数模版
- 实例化函数模版(C++)
- 模版函数
- 模版函数
- 模版函数
- 函数模版
- 函数模版
- 函数模版
- 函数模版
- Hexo 添加百度统计
- android Activity切换屏 生命周期变化问题
- php学习之五(面向对象)
- 我的第一次Unity游戏开发历程
- maven快照版本和发布版本
- c++中的函数模版
- Delphi中TResourceStream流使用
- 查找整数
- 217. Contains Duplicate(C语言)
- html table 边框设置
- Elasticsearch java api(五) Bulk批量索引
- 我的软件工程课目标
- 移植libnopoll到SylixOS技术笔记
- 车牌识别之车牌定位