-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exercise 2.15(b) confusing #71
Comments
yes.
const reference is different from plain reference. const int &i = 1.01; // i refers to temporary with value 2.0 Thus, in your example, the const reference is not bound to double literal, rather than the temporary(object). please check: http://en.cppreference.com/w/cpp/language/reference_initialization FYI |
Hi, @pezy,
While I try to compile codes like:
gcc-c++ compiler (version:4.9.2) don't throw a(n) warning or error to me as I expect and its outputs are correct. And of course I know that assign this kind of variable name is inappropriate, I just wanna know whether modern C++ explicitly forbid such behaviors or not. |
No. It's just a coding style... (established by usage) |
@pezy Got it and thank you. I found that almost, well actually every variable name I can find in C++ headers start with underscores, like |
Exactly. 😄 |
@pezy A big thanks! |
Do you mean 1.01 (double literal) is not an object,so the reference can't be bound to 1.01?
But
const int &i=1.01
is valid.So i think the necessity of const should be the answer.The text was updated successfully, but these errors were encountered: