函数:模板的使用

来源:互联网 发布:bitcomet mac版 编辑:程序博客网 时间:2024/05/21 16:07
#include<iostream>template <typename T>void Swap(T &a, T &b);int main(void){using std::cout;int i=10, j=20;cout << "i,j = " << i << ", " << j << ".\n";cout << "Using compiler-generated int swapper:\n";Swap(i,j);cout << "Now i, j = " << i << ", " << j << ".\n";double x=24.5, y=81.7;cout << "x, y = " << x << ". " << y << ".\n";cout << "Using compiler-generated int swapper:\n";Swap(x,y);cout << "Now x, y = " << x << ", " << y << ".\n";return 0;}template <typename T>void Swap(T &a, T &b){T temp;temp = a;a = b;b = temp;}

原创粉丝点击