二、函数模板的使用
有两种使用方式
- 自动类型推导 (根据代码的上下文自动推导出传入变量的数据类型)
 - 显式指定类型(传入变量的时候显式的指定数据类型)
 
#include <iostream>using namespace std;template<typename T> // 声明一个模板void mySwap(T& t1,T& t2 ){T temp = t1;t1 = t2;t2 = temp;}int main(){int a = 10;int b = 20;// 1、自动类型推导// mySwap(a,b);// 2、显式指定类型mySwap<int>(a,b);cout << "a = " << a << endl;cout << "b = " << b << endl;system("pause");return 0;}
