c++ 函数模板

VC6.0编译通过,eclipse没有通过。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
  #include <iostream>
using namespace std;
 
//int max(int x, int y)
//{
//     cout << "调用int max(int x, int y);" << endl;
//     return x > y ? x : y;
//}
//float max(float x, float y)
//{
//     cout << "调用float max(float x, float y);" << endl;
//     return x > y ? x : y;
//}
 
template <class T>
T max(T x, T y)
{
    cout << "调用模板" << endl;
    return x > y ? x : y;
}
 
int main()
{
    cout << max(2,3) << endl;
    cout << max(2.0f,3.0f) << endl;
//     cout << max(2.0d,3.0d) << endl;
    return 0;
}
原文地址:https://www.cnblogs.com/helloweworld/p/2687688.html