#include<iostream>
using namespace std;
int max_(int a,int b){
return (a>b?a:b);
}
double max_(double a,double b){
return (a>b?a:b);
}
long max_(long a,long b){
return (a>b?a:b);
}
int main(){
int a=1,b=0;
cout<<max_(a,b);
double a_=2,b_=0;
cout<<max_(a_,b_);
long A=3,B=0;
cout<<max_(A,B);
return 0;
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/ab671386e5a5b1bb2ce324e28da7a736.png#pic_center)
#include<iostream>
using namespace std;
template<typename T>
T abs(T x){
return x<0?-x:x;
}
int main(){
int a=1;
double b=-1;
cout<<abs(a)<<' '<<abs(b);
return 0;
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/8b0b2488376c12fe7fd170359a39d8b2.png#pic_center)
#include<iostream>
using namespace std;
template<class T>
T add(T a,T b){
return a+b;
}
int main(){
cout<<add(1,2)<<endl;
cout<<add(1.0,23.2)<<endl;
cout<<add('1','0')<<endl;
return 0;
}