Why the code is not working?🤔🤔 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
3rd Oct 2019, 12:33 PM
Vivek Raj
Vivek Raj - avatar
2 Answers
+ 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.
3rd Oct 2019, 12:48 PM
Zeke Williams
Zeke Williams - avatar
+ 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
3rd Oct 2019, 12:42 PM
Schindlabua
Schindlabua - avatar