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;
}
 
0 0
原创粉丝点击