It makes some intuitive sense why const
is necessary here, as the number hasn't really gotten a place to land so you can't pass it by reference, but is there a more formal explanation?
#include <iostream>
int number()
{
return 8;
}
int greet(const int& q)
{
std::cout << "HI!";
return q;
}
int main()
{
return greet(number());
}