#include <iostream.h>
void
SwapWrong( int A, int B )
{
int Tmp = A;
A = B;
B = Tmp;
}
void
SwapPtr( int *A, int *B )
{
int Tmp = *A;
*A = *B;
*B = Tmp;
}
void
SwapRef( int & A, int & B )
{
int Tmp = A;
A = B;
B = Tmp;
}
template <class Etype>
void
Swap(Etype & Lhs, Etype & Rhs)
{
Etype Tmp = Lhs;
Lhs = Rhs;
Rhs = Tmp;
}
main( )
{
int X = 5;
int Y = 7;
SwapWrong( X, Y );
cout << "X=" << X << " Y=" << Y << '\n';
SwapPtr( &X, &Y );
cout << "X=" << X << " Y=" << Y << '\n';
SwapRef( X, Y );
cout << "X=" << X << " Y=" << Y << '\n';
Swap(X, Y);
double a =0, b =5;
Swap(a, b);
return 0;
}