/*3
howdy
3.2
1*/
#include <iostream>
using namespace std;
//在此处定义myMax模板函数
template <typename T>
T myMax(T a, T b){
if(a>b){
return a;
}else{
return b;
}
}
int main(){
cout << myMax(3,2) << endl;
cout << myMax(string("hello"),string("howdy")) << endl;
cout << myMax(3.2,0.5) << endl;
cout << myMax(true,false) << endl;
return 0;
}

本文介绍了如何在C++中定义一个名为myMax的模板函数,用于比较不同类型的数据(整数、字符串、浮点数和布尔值),并展示了在main函数中的使用实例。
6363

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



