+ 3
Why the code is not working?🤔🤔
2 ответов
+ 5
https://code.sololearn.com/cm1dEBXn0Jl3/?ref=app
A couple things. You placed integer literals into your swap call. There's no point to swapping values that have no variable reference attached to them, so I made int's a and b. It works without a and b though.
Second, swap is already defined in C++, so it thought you were trying to overload it. I named it swaps to fix this.
Third, you called swap within another function who's arguments were not references, but values instead. That is fine as long as you only need the swap to exist within the scope of that function, so this is just for your info.
+ 5
The std namespace already has a `swap` function that does the same thing as your function and so C++ is unsure which one to choose.
That's why `using namespace std` is a bad idea! Your two options are
- remove `using namespace std`
- rename your swap function