我开始学习模板,并从书中复制了代码,但编译器给了我这个错误
错误 1 错误:“交换”:对重载函数的模糊调用”
这是我的程序
#include <iostream>
template <typename X>
void swap(X &a, X &b);
int _tmain(){
using namespace std;
int a, b;
cout << "enter two numbers:\n";
cin >> a >> b;
cout << "Your numbers are: " << a << ", " << b << endl;
swap(a, b); //error is here
cout << "Your numbers reversed are: " << a << ", " << b << endl;
return 0;
}
template <typename X>
void swap(X &a, X &b){
X temp = a;
a = b;
b = temp;
}