Today I came across a strange situation when I needed a function to implicitly convert values.
After browsing google, I found http://www.devx.com/cplus/10MinuteSolution/37078/1954
But I thought it would be a little silly to use the overload function for every other type that I want to block, so I did it.
void function(int& ints_only_please){}
int main()
{
char a=0;
int b=0;
function(a);
function(b);
}
I showed the code to a friend and he suggested that I added const to int, so the variable is not editable, however, when I started to compile, but should not, look below to see what I mean
void function(const int& ints_only_please){}
int main()
{
char a=0;
int b=0;
function(a); //Compiler should stop here but it doesn't with const int
function(b);
}
Does anyone know why this is?
source
share