Recently I have written one function which is doing some processing on double numbers but due to some change I need to do same processing for integers so to cut the long story short with simpler example as given below :
void display(double& arg)
{
std::cout << arg << std::endl;
}
int main()
{
int inum = 10;
display(inum);
return 0;
}
I found that above code is not compiling and giving error "reference of type "double &" (not const-qualified) cannot be initialized with a value of type "int", since the error is quite intuitive so i modified the code and changed the argument of display function to const double& arg and everything seems to be working correctly.So my question is
What exactly is happening in the "const double&" case? A full explanation is desired?
Now after reading some of the explanation and question link that is provided i understood that conversion produces rvalue and rvalue cannot be bound to temporaries so the only reasoning i m looking for is why conversion produces rvalue ?