Why these two functions are ambigous though their mangled names are different

55 views Asked by At

Consider the following function definitions:

void fun(int& a)
{
    cout << "Ra" << endl;
}

And:

void fun(int a)
{
    cout << "a" << endl;
}

Now, when I call the function like this:

int a;
fun(a);

The call is ambiguous, because the compiler can't decide whether to call by value or by reference.

My Question is:

When I write something like this:

int a;
int &b = a;
fun(b);

It again gives ambiguity. Since b is a reference, so why not call the one where the argument is a reference.

I already saw the answers in this question: Function Overloading Based on Value vs. Const Reference but it doesn't answer my question. Please Help.

0

There are 0 answers