在C++中,对模板函数有两种重载方法,一是利用函数模板的函数体;二是重新定义函数体。哪位C++高手能告诉下面一段程序在GNU下面的有什么问题(利用第一种方法重载模板函数)
#include <iostream.h>
template <class T>
T max (T x, T y)
{
cout << "This is the template function! max is: ";
return (x>y) ? x:y;
}
int max(int, int);
char max(char, char);
main()
{
int i = 10;
char c = 'a';
float f = 43.74;
cout << max(i,i) << "\n";
cout << max(c,c) << "\n";
cout << max(i,c) << "\n";
cout << max(c,i) << "\n";
cout << max(f,f) << "\n";
cout << max(f,i) << "\n";
return 1;
}
#include <iostream.h>
template <class T>
T max (T x, T y)
{
cout << "This is the template function! max is: ";
return (x>y) ? x:y;
}
int max(int, int);
char max(char, char);
main()
{
int i = 10;
char c = 'a';
float f = 43.74;
cout << max(i,i) << "\n";
cout << max(c,c) << "\n";
cout << max(i,c) << "\n";
cout << max(c,i) << "\n";
cout << max(f,f) << "\n";
cout << max(f,i) << "\n";
return 1;
}