#include <stdio.h>
#include <stdlib.h>
template<typename A>
A AddTwo(A a,A b)
{
printf("its defailt.\n");
return a + b;
}
//一般将特化模板函数定义放在缺省模板函数下面。
int AddTwo(int a,int b)
{
printf("its int ####.\n");
return a + b;
}
char AddTwo(char a,char b)
{
printf("its char ####.\n");
return a + b;
}
int main()
{
float a = 10,b = 20;
printf("sum %d.\n",AddTwo(a,b));
int a = 10,b = 20;
printf("sum %d.\n",AddTwo(a,b));
char a = 10,b = 20;
printf("sum %d.\n",AddTwo(a,b));
return 0;
}
AddTwo函数会根据类型自动匹配到对应的特化函数