标题:[求助]用模板时的一个错误??
取消只看楼主
kongkong0926
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2006-9-14
 问题点数:0 回复次数:0 
[求助]用模板时的一个错误??

#include <iostream>
using namespace std;

template<typename T>
void swap(T &a,T &b);

int main()
{
int i=10;
int j=20;
cout<<"i="<<i<<",j="<<j<<endl
<<"after swap:"<<endl;
swap(i,j);
cout<<"i="<<i<<",j="<<j<<endl;
return 0;
}

template<typename T>
void swap(T &a,T &b)
{
T temp;
temp=a;
a=b;
b=temp;
}

errors:
E:\VC\10-31\aa.cpp(13) : error C2667: 'swap' : none of 2 overload have a best conversion
E:\VC\10-31\aa.cpp(13) : error C2668: 'swap' : ambiguous call to overloaded function

搜索更多相关主题的帖子: 模板 
2006-10-30 21:40



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-99797-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.326668 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved