How is this even possible

closed account (EwCjE3v7)
Hi there,
I just came around this and don't understand how a const reference can do this with out.
 
  const int &ri = 0;

How is that possible?
Without the const I get an error but with const I don't. Why?
Thanks
I have never seen this used before but this topic might be able to answer some questions about it.
http://www.cplusplus.com/forum/beginner/19479/

This quote from guestgulkan seems to sum it up pretty well.

You can't take the address of a literal (so the address of a literal cannot be assigned to a pointer).

references are not pointers (in the c++ sense) and behave differently with regards to literals.
You can bind a reference to a literal because
a temporary variable is created from the literal and the and it is this temporary variable that is used by the the reference. Temporary variables are constant.
closed account (EwCjE3v7)
thanks James
i had something like that in my book but forgot about it
thanks
Topic archived. No new replies allowed.