用函数重载交换数据
#include <iostream>
using namespace std;
void fun()
{
int a=1;
int b=2;
a=a^b;
b=a^b;
a=a^b;
cout << "a1=" << a << " " << "b1=" << b << endl;
}
void fun(double a,double b)
{
double temp;
temp=a;
a=b;
b=temp;
cout << "a2=" << a << " " << "b2=" << b << endl;
}
void fun(char a,char b)
{
a=a^b;
b=a^b;
a=a^b;
cout << "a3=" << a << " " << "b3=" << b << endl;
}
void fun(string a,string b)
{
string temp;
temp=a;
a=b;
b=temp;
cout << "a4=" << a << " " << "b4=" << b << endl;
}
int main()
{
fun();
fun(1.11,2.22);
fun('a','b');
fun("aaa","bbb");
return 0;
}