-
#include <iostream>
-
using namespace std;
-
-
template <typename AnyType>
-
void Swap(AnyType &a, AnyType &b)
-
{
-
AnyType tmp;
-
tmp = a;
-
a = b;
-
b = tmp;
-
}
-
-
int main(int argc, char **argv)
-
{
-
int a = 1;
-
int b = 2;
-
cout << "a = " << a <<", b = " << b <<endl;
-
Swap(a, b);
-
cout << "a = " << a <<", b = " << b <<endl;
-
return 0;
-
}
-
template <typename AnyType>
表示要建立一个模板,类型为AnyType,关键字为
template ,typename (class)
阅读(807) | 评论(0) | 转发(0) |