#include<iostream>
using namespace std;
template<typename T>
void swap(T &a,T &b)
{
T temp;
temp=a;
a=b;
b=temp;
}
template<typename T>
void display(T a,T b)
{
cout<<a<<"\t"<<b<<endl;
}
void main()
{
int a=1,b=2;
float c=2.4,d=45.2;
char e='s',f='k';
swap(a,b);
}
出现多个重载函数“swap”实例与参数列表匹配的原因是:
标准库为我们定义了一个模板化的swap函数,可以使用std::swap使用。 所以这里就会出现重定义,系统无法分辨用哪一个。 我们只需要改动名字Swap就能使程序正常运行