I'm having an hard time understanding both the usefulness and the reason why I am allowed to write something as:
I understand I couldn't do this if I hadn't declared the reference as const. I also understand that the compiler transforms that code into something like:Code:const int &ref = 12;
However, I cannot conceive a single use for this const reference initialized to a literal. Is there any?Code:const int temp = 12; //create a temporary object const int &ref = temp; //bing the reference to the temporary object;
Another problem is why am I allowed to intialize to a literal? I can understand why I am not on the case of non const references, but why am I on const references? Even on the highest warning level for C++ 2005 Express and using -Wall and -Wextra on Dev-Cpp I get no single warning.