Calling swap(first, second) gives me an error: call of overloaded 'swap(double&, double&)' is ambiguous. I'm not sure how this call is ambiguous when first and second are doubles and not pointers to anything. Also, the first swap() takes in two arguments, but the second one takes in three.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354`` `````` const int Arsize = 10; template void swap(Any &, Any &); template void swap(Any*, Any*, int sizer); template void show(Any*, int sizer); using namespace std; int main(void) { double first = 3; double second = 4.6; cout << "First: " << first << " Second: " << second << "\n"; swap(first, second); cout << "First: " << first << " Second: " << second << "\n"; int firs[Arsize] = {0,4,1.6,9,1,9,7,6}; int secon[Arsize] = {0,2.4,1,4,2,0,0,1}; show(firs, Arsize); show(secon, Arsize); swap(firs, secon, int(Arsize)); show(firs, Arsize); show(secon, Arsize); return 0; } template void swap(Any&a, Any&b) { Any temp = a; a = b; b = temp; } template void swamp(Any*pa, Any*pb, int sizer) { for(int i = 0; i void show(Any*pa, int sizer) { cout << pa[0] << pa[1] << "/" << pa[2] << pa[3] << "/"; for(int i = 0; i<4; i++) cout << pa[i]; cout << "\n"; } ``````
Last edited on
Which call(s) are ambiguous exactly?
It really helps if you tell us which of those calls is giving you the error.

EDIT:

Oh wait... okay I see it.

This is a namespace issue. Your swap function is conflicting with std::swap because you are doing `using namespace std;`

This is exactly why using namespace std; is discouraged. The whole point of having namespaces is to avoid name conflicts. When you dump the entire std namespace into the global namespace, it defeats the entire point of putting it in a namespace to begin with.

Either name your swap function something else... or put it in a namespace.... or don't dump std::swap into the global namespace.
Last edited on
Calling swap(first, second)
Topic archived. No new replies allowed.