Quantcast
Channel: Visual C forum
Viewing all articles
Browse latest Browse all 15302

ambiguity in function overloading

$
0
0

Hi all,

Now I am learning about the ambiguity in function overloading.

So I written a small program

void f1( long a )

{

}

void f1(char a )

{

}

void Somefunc()

{

Int b = 20000;

f1( b );

}

Here my compiler (VC 2010) complaining the call is ambiguous.

But I think according to the overloading rules promotions have more priority than standard conversions.

Here I think int to char have data lose and definitely needs the standard conversion.

But I don’t think int to long have any data lose (I think according to C++ standards long will be always bigger than int in size)

So I think int to long only need a promotion. Am I right?

If it only needs a promotion how the above function call is ambiguous? Compiler can clearly choose the f1 (long) na?

please help me to understand the concepts


Viewing all articles
Browse latest Browse all 15302


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>