Posted on 2006-02-28 22:55
quite 阅读(653)
评论(5) 编辑 收藏 引用 所属分类:
求助
//这是个关于函数模板的问题,不明白为什么会出现这样的错误,希望前辈们花二分钟看一下,拜托了啊。 (这是<C++ Pirmer Plus >第五版
//中的程序,我用的是 Visual C++6.0)
#include<iostream>
using namespace std;
template <class type>
void swap(type &a,type &b)
{
type temp;
a=b;
b=temp;
}
int main()
{
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<<endl;
/*double x=24.5;
double y=81.7;
cout<<"x,y="<<x<<","<<y<<endl;
cout<<"Using compiler_generated double swapper:\n";
swap(x,y);
cout<<"Now x,y="<<x<<","<<y<<endl;*/
return 0;
}
error C2667: 'swap' : none of 2 overload have a best conversion
E:\Documents and Settings\bing\桌面\8.11_funtemp.cpp(14) : error C2668: 'swap' : ambiguous call to overloaded function