0
votes

Not sure what the problem is..

$ g++ test2.C test2.C: In function 'int main()': test2.C:25: error: call of overloaded 'swap(int&, int&)' is ambiguous test2.C:8: note: candidates are: void swap(T&, T&) [with T = int] /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algobase.h:92: note: void std::swap(_Tp&, _Tp&) [with _Tp = int]

#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

template <class T>
inline void swap(T& i, T& j) { 
T temp = i; i = j; j = temp;
}




main() {
int m,n;
cout << "Enter integer :";

cin >> m;
cout << "Enter integer :";

cin >> n;
cout << m << "," << n << endl;

swap(m,n);

cout << m << "," << n << endl;
}
1
Instead of making your title unique by adding "(newbie)", choose a real title which describes your problem. Figure out why your problem is different from the existing question with the same title. If you can't figure that much out, your question is probably a duplicate and shouldn't be asked in the first place.meagar♦

1 Answers

3
votes

Try naming your swap myswap (or anything else) or putting it in a namespace

because you have using namespace std; it is confused between your swap and std::swap

In general always avoid using namespace std; Definately in headers but as here, it can cause problems in .cpp files as well