-4

note: candidate: 'std::_Requirestd::__not_<std::__is_tuple_like<_Tp >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > std::swap(_Tp&, _Tp&) [with _Tp = int; std::_Requirestd::__not_<std::__is_tuple_like<_Tp >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > = void]' 196 | swap(_Tp& __a, _Tp& __b) | ^~~~

 #include <iostream>
using namespace std;
template <class T>
void swap(T & x, T & y)
{
    T t;
    t = x;
    x = y;
    y = t;
}
main(void)
{
    char ch1, ch2;
    cout << "Enter the characters a and b: ";
    cin >> ch1 >> ch2;
    swap(ch1, ch2);//error here
    cout << "On swapping ch1 and ch2: " << ch1 << " " << ch2 << endl;
    int a,b;
    cout << "Enter the characters a and b: ";
    cin >> a >> b;
    swap(a, b);//error here
    cout << "On swapping ch1 and ch2: " << a << " " << b << endl;
}
Rajiv
  • 1
  • 1
  • 1
    `using namespace std;` is one of the problems as there is a `std::swap`. See [Why is "using namespace std;" considered bad practice?](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice) – Richard Critten May 11 '22 at 15:23
  • Rename your swap routine to `rajiv_swap`, so it doesn't collide with `std::swap`. – Eljay May 11 '22 at 15:26
  • I am strongly of the opinion that the horrible `using namespace std;` is causing the issues here. Whoever told you to do that -- tell them they are wrong. Remove it. Also, you have not supplied us with the `error:` you are getting. What you show is a `note:` about the error, mentioned to you elsewhere. – Drew Dormann May 11 '22 at 15:28
  • `main(void)` is also wrong and the compiler should complain about it. It should be `int main()` or `int main(void)`. The `void` is optional and serves no purpose, so it is usually not written. – user17732522 May 11 '22 at 15:42

0 Answers0