我想使用C++模板仿製藥爲void功能,使用模板與空函數
代碼:
#include <iostream>
using namespace std;
template <typename T>
inline void swap(T& x, T& y)
{
T temp = x;
x = y;
y = temp;
}
int main()
{
cout << "Swapper!" << endl;
int x, y;
cin >> x >> y;
swap(x, y);
cout << x << y;
cin.get();
return 0;
}
但它給出了一個錯誤:
通話超載swap()含糊不清
如何刪除此錯誤?
我認爲重複並沒有完全解決爲什麼'std :: swap'可能成爲一個問題,即使既沒有''也沒有''被包括在內。 –