#include <iostream>
using namespace std;
void somefunc(int a)
{
cout<<"somefunc1";
}
void somefunc(int &b)
{
cout<<"somefunc2";
}
int main()
{
// case 1
somefunc(10); // works fine and prints somefunc1
//case2
int b=10;
somefunc(b); // generates compiler error that overloading is ambiguous
return 0;
}
In main() if I pass a constant (say 10) program compiles and runs and prints "somefunc1", but when I pass a variable (b in this case) compiler generates an error that overloading is ambiguous.
I don't understand how is it working internally. Please help!!
const int c = 10;) would produce a different result. Why passingcis different from passingbis left as an exercise to the reader.