error of overloaded function

Hi all, I have the following simple example of function overload, but I can not get it to run cause I get the following error message:
error: call of overloaded 'swap(double& , double&)' is ambiguous. any help will be appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include<iostream>

template <typename any> // fct template prototype
void swap(any &a, any &b);

int main()
{
    using namespace std;
    int i = 10;
    int j = 20;
    cout << "i, j = " << i << ", " << j << ".\n";
    cout << "using compiler-generated int swapper: \n";
   // swap(i, j); //generates void swap(int &, int &)
    cout << "now i, j= " << i <<", " << j << ".\n";

    double x = 24.500000;
    double y = 81.700000;
    cout << "x, y = " << x << ", " << y << ".\n";
    cout << "using compiler-generated double swapper: \n";
    swap( x,  y);
    cout << "now x, y= " << x <<", " << y << ".\n";

    return 0;
}

//function template definition
template <typename any>
void swap(any &a, any &b)
{
    any temp;
    temp = a;
    a = b;
    b = temp;
}


closed account (1vRz3TCk)
There is a std::swap and your swap. because of the using namespace std; the compiler doesn't know which to use. Try ::swap( x, y); to tell it to use your swap.
thank you CodeMonkey, you are 100% right, I changed the swap() to Swap() and it did not complain. Sorry for this stupid question, I am just a beginner :(.
closed account (1vRz3TCk)
If you don't know the answer, no question is stupid. :0)
Topic archived. No new replies allowed.