I was trying to write an overloaded function to accept both signed and unsigned integers.
Following is my code:
#include <iostream>
void fun(const long long a)
{
std::cout << "Signed: " << a << std::endl;
}
void fun(const unsigned long long a)
{
std::cout << "unsigned: " << a << std::endl;
}
int main()
{
unsigned int v = 10;
fun(v);
return 0;
}
This gives the following compilation error.
main.cpp:17:5: error: call to 'fun' is ambiguous
fun(v);
^~~
main.cpp:4:6: note: candidate function
void fun(const long long a)
^
main.cpp:9:6: note: candidate function
void fun(const unsigned long long a)
^
1 error generated.
I was assuming it would work just fine, as unsigned int
can be represented by the unsigned long long
type.
Can anyone please help me understand this error?