OOP of template , for int and double
(高顯忠, sjgau4311@gmail.com, 2010-12-22 11:45)
1樓
// file name: rand-02.cpp
#include "sj-01.h"
#include "sj-02.h"
// ----------------------------------------------
using namespace std;
// ----------------------------------------------
// swap2(a, b);
template <class T>
void swap2(T *a, T *b)
{
T temp;
temp= *a;
*a= *b;
*b= temp;
}// end of swap2()
// ----------------------------------------------
#if 0
#endif
// ----------------------------------------------
int main(int argc, char *argv[])
{
int a, b;
double m, n;
a= 123456; b= 456789;
printf("\n before the swap, a= %d, b= %d\n", a, b);
swap2(&a, &b);
printf("\n after the swap, a= %d, b= %d\n", a, b);
system("pause");
// ------------------------------------------
m= 1212.34; n= 5656.78;
printf("\n before the swap, m= %.6lf, n= %.6lf\n", m, n);
swap2(&m, &n);
printf("\n after the swap, m= %.6lf, n= %.6lf\n", m, n);
system("pause");
return EXIT_SUCCESS;
}// end of main()