094-C++

来源:互联网 发布:java开发框架课程设计 编辑:程序博客网 时间:2024/06/10 08:28

函数模板

#include <iostream>#include <string> using namespace std; template <typename T>inline T const& Max (T const& a, T const& b) {     return a < b ? b:a; } int main (){     int i = 39;    int j = 20;    cout << "Max(i, j): " << Max(i, j) << endl;      double f1 = 13.5;     double f2 = 20.7;     cout << "Max(f1, f2): " << Max(f1, f2) << endl;      string s1 = "Hello";     string s2 = "World";     cout << "Max(s1, s2): " << Max(s1, s2) << endl;     return 0;}


原创粉丝点击