由于返回值类型没有办法直接推导出来,所以需要显式指定出来,当然也有其他方法,我就不太清楚了,看这个例子:
#include
using namespace std;
template
T1 Max(T2 a,T3 b)
{
T1 temp;
if(a>b)
temp=a;
else
temp=b;
return static_cast
}
int main()
{//int Max(short a,int b);
short a=1;
int b=2;
cout<<"max:"<
return 0;
}
希望能帮到你
可以的,就是你传入的类型