为什么编译一直通不过呢?
#include <iostream>
using namespace std;
/**
* 定义模板函数swapNum
* 实现功能:交换两个数的位置
*/
template <typename T>
void swap(T &a,T &b)
{
T temp = a;
a = b;
b = temp;
}
int main(void)
{
int x = 10;
int y = 20;
// 调用模板函数
swap<int>(x,y);
cout << "x = " << x << endl;
cout << "y = " << y << endl;
return 0;
}
l报错:/477/9670/FmcL/index.cpp: In function 'int main()':
/477/9670/FmcL/index.cpp:22:18: error: call of overloaded 'swap(int&, int&)' is ambiguous
swap(x,y);
^
/477/9670/FmcL/index.cpp:22:18: note: candidates are:
/477/9670/FmcL/index.cpp:9:6: note: void swap(T&, T&) [with T = int]
void swap(T &a,T &b)
^
In file included from /usr/include/c++/4.8.2/bits/stl_pair.h:59:0,
from /usr/include/c++/4.8.2/bits/stl_algobase.h:64,
from /usr/include/c++/4.8.2/bits/char_traits.h:39,
from /usr/include/c++/4.8.2/ios:40,
from /usr/include/c++/4.8.2/ostream:38,
from /usr/include/c++/4.8.2/iostream:39,
from /477/9670/FmcL/index.cpp:1:
/usr/include/c++/4.8.2/bits/move.h:166:5: note: void std::swap(_Tp&, _Tp&) [with _Tp = int]
swap(_Tp& __a, _Tp& __b)
^