// hanshu_muban.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
using namespace std;
template <typename T> void Swap(T *a, T *b){
T temp = *a;
*a = *b;
*b = temp;
}
int _tmain(int argc, _TCHAR* argv[])
{
int n1 = 100;
int n2 = 200;
Swap(&n1, &n2);
cout << n1 << ", " << n2 << endl;
//交换 float 变量的值
float f1 = 12.5, f2 = 56.93;
Swap(&f1, &f2);
cout << f1 << ", " << f2 << endl;
//交换 char 变量的值
char c1 = 'A', c2 = 'B';
Swap(&c1, &c2);
cout << c1 << ", " << c2 << endl;
//交换 bool 变量的值
bool b1 = false, b2 = true;
Swap(&b1, &b2);
cout << b1 << ", " << b2 << endl;
getchar();
return 0;
}
运行结果: