S
subramanian100in
Consider the following program:
#include <iostream>
using namespace std;
void print(char c)
{
cout << "from print(char c) : " << c << endl;
return;
}
void print(long c)
{
cout << "from print(long c) : " << c << endl;
return;
}
int main()
{
int i = 100;
print(i);
return 0;
}
When I compile the program I am getting the following compilation
error:
'print' : ambiguous call to overloaded function
could be 'void print(long)'
or 'void print(char)'
while trying to match the argument list '(int)'
int to char requires standard conversion.
But isn't integer promoted to long similar to the way short is
promoted to int ? If int is promoted to long, the ambiguity will not
arise. This is what I expected. But it does not happen. Kindly explain
the reason.
Thanks
V.Subramanian
#include <iostream>
using namespace std;
void print(char c)
{
cout << "from print(char c) : " << c << endl;
return;
}
void print(long c)
{
cout << "from print(long c) : " << c << endl;
return;
}
int main()
{
int i = 100;
print(i);
return 0;
}
When I compile the program I am getting the following compilation
error:
'print' : ambiguous call to overloaded function
could be 'void print(long)'
or 'void print(char)'
while trying to match the argument list '(int)'
int to char requires standard conversion.
But isn't integer promoted to long similar to the way short is
promoted to int ? If int is promoted to long, the ambiguity will not
arise. This is what I expected. But it does not happen. Kindly explain
the reason.
Thanks
V.Subramanian