using namespace std;//template告訴C++編輯器要進行泛型編程 T在這里是一種類型template<typename T>//數(shù)據(jù)類型參數(shù)化void myswap(T &a,T &b){ T t = a; a = b; b = t;}void main(){ int a1 = 10; int b1 = 20; myswap(a1,b1);//這是最容易董的函數(shù)調(diào)用方式 cout<<"a1="<<a1<<endl; cout<<"b1="<<b1<<endl; myswap<int>(a1,b1); cout<<"a1="<<a1<<endl; cout<<"b1="<<b1<<endl; system("pause");}
新聞熱點
疑難解答