|
下面是Linux下一段代码,报出错误:call of overloaded 'swap(int &, int&)' is ambiguous 等等
同样我把代码写在VC++6.0上也报出错误:ambiguous call to overloaded function
希望大家帮我看下,如何解决呢,谢谢大家。
code in VC++6.0 (在Linux下头文件需要指明路径):
#include <iostream>
template <class Any>
void swap(Any &a, Any &b);
int main()
{
using namespace std;
int i= 10;
int j= 20;
cout << "Using complier-generatd int swapper.\n";
swap(i, j);
cout << "i, j = " << i << ", " << j << ".\n";
double x= 24.5;
double y= 81.7;
cout << "Using complier-generatd double swapper.\n";
swap(x, y);
cout << "x, y = " << x << ", " << y << ".\n";
return 0;
}
template <class Any>
void swap(Any &a, Any &b)
{
Any temp;
temp= a;
a= b;
b= temp;
} |
|