#include<iostream>usingnamespace std;template<typenameT>voidmySwap(T &a, T &b)// 两数交换模板{
T temp = a;
a = b;
b = temp;}// template<> void mySwap(int &a, int &b) // 解注释的话发生函数重载 a b 均变为 100// {// a = 100;// b = 100;// }intmain(){int a =10;int b =20;// 使用方法一:自动推导mySwap(a, b);
cout << a << b << endl;// 20 10// 使用方法二:指定类型mySwap<int>(a, b);
cout << a << b << endl;// 10 20}