函数模板类型转换不成功~~
:\c++程序\zy_8_11\11.cpp(11) : error C2667: 'swap' : none of 2 overload have a best conversionD:\c++程序\zy_8_11\11.cpp(11) : error C2668: 'swap' : ambiguous call to overloaded function
D:\c++程序\zy_8_11\11.cpp(17) : error C2667: 'swap' : none of 2 overload have a best conversion
D:\c++程序\zy_8_11\11.cpp(17) : error C2668: 'swap' : ambiguous call to overloaded function
Error executing cl.exe.
zy_8_11.exe - 4 error(s), 0 warning(s)
#include <iostream>
template<class Any>
void swap(Any &a,Any &b);
int main()
{
using namespace std;
int i=10;
int j=20;
cout<<"i,j= "<<i<<" ."<<j<<endl;
cout<<"using compiler -generated int swapper:\n";
swap(i,j);
cout<<"NOw i,j= "<<i<<". "<<j<<"\n";
double x=24.5;
double y=81.7;
cout<<"x,y = "<<x<<" ."<<y<<endl;
swap(x,y);
cout<<"NOwx,y= "<<x<<" ."<<y<<endl;
return 0;
}
template<class Any>
void swap(Any& a, Any& b)
{
Any temp;
temp=a;
a=b;
b=temp;
}