用函数模板实现两个数值交换
#include<iostream>
using namespace std;
//用模板实现两个数值交换
template<class T>
void tswap( T *x, T *y)
{
int temp = *x;
*x = *y;
*y = temp;
}
void main()
{
int a = 5,b = 10;
cout << "a,b 的值:" << a << "," << b << endl;
tswap(&a, &b);
cout << "a,b 的值:" << a << "," << b << endl;
}