我目前使用的是 C++ 17,我想简化我的程序。但是,我被抛出错误:
more than one instance of overloaded function \"swap\" matches the argument list: -- function template \"void swap(T &a, T &b)\" -- function template \"std::enable_if<std::__and_<std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp>>::value, void>::type std::swap(_Tp &__a, _Tp &__b)\" -- argument types are: (int, int)",
Run Code Online (Sandbox Code Playgroud)
这是我写的代码:
#include <iostream>
#include <string>
using namesapce std;
template <typename T>
void swap(T &a, T &b) {
T temp = a; //Temporary copy to reuse
a = b;
b = temp;
}
int main() {
int x, y;
cin >> x …Run Code Online (Sandbox Code Playgroud)