using namespace std;//template告诉C++编辑器要进行泛型编程 T在这里是一种类型template<typename T>//数据类型参数化void myswap(T &a,T &b){ T t = a; a = b; b = t;}void main(){ int a1 = 10; int b1 = 20; myswap(a1,b1);//这是最容易董的函数调用方式 cout<<"a1="<<a1<<endl; cout<<"b1="<<b1<<endl; myswap<int>(a1,b1); cout<<"a1="<<a1<<endl; cout<<"b1="<<b1<<endl; system("pause");}
新闻热点
疑难解答