#include <iostream>
#include<string>
using namespace std;
void swapInt(int& a, int& b)
{
int temp = a;
a = b;
b = temp;
}
void swapDauble(double& a, double& b)
{
double temp = a;
a = b;
b = temp;
}
//函数模板
template<typename T>//声明一个模板,告诉编译器后面代码中紧跟着T不要报错,T是一个通用数据类型
void mySwap(T& a, T& b)
{
T temp = a;
a = b;
b = temp;
}
void test01()
{
int a = 10;
int b = 20;
//swapInt(a, b);
//两种方式利用函数模板
//1.自动类型推导
//mySwap(a, b);
//2.显示指定类型
mySwap<int>(a, b);
cout << "a=" << a << endl;
cout << "b=" << b << endl;
}
int main() {
test01();
}