C++函数模板例子

//C++函数模板实例

#include <iostream>
template <class Any>
void Swap(Any &a, Any &b);

int main()
{
    using namespace std;
    double i = 10.123, j = 20.124;

    Swap(i, j);
   
    cout << "i, j = " << i << " ," << j << endl;

   

    return 0;
}

template <class Any>
   
void Swap(Any & a, Any & b)
{
    Any temp;
    temp = a;
    a = b;
    b = temp;
}

 

posted @ 2013-07-22 19:01  夕相待  阅读(432)  评论(0编辑  收藏  举报