I am just starting learning c++. I found an advice on Internet: "Learn with a good book, it is better than videos on youtube." So as I am motivated and I have time I learn with c++ Primer 5th Ed.
In this book, they say: Note: "A reference is not an object. Instead, a reference is just another name for an already existing object."
and: "a reference may be bound only to an object, not to a literal or to the result of a more general expression"
I understand:
int i = 3;
int &ri = i; // is valid: ri is a new name for i
int &ri2 = 2; // is not valid: 2 is not an object
Then I don't understand why:
const int &ri3 = 2; // is valid
They write: "It can be easier to understand complicated pointer or reference declarations if you read them from right to left."
Ok, it is not very complicated. I understand: I declare a variable named ri3, it is a reference (a reference when & is after the type, an address when & is in an expression) to an object of type int and it is a constant.
I think it has already been explained many times but when I search on forums I find complicated (to me) answers to complicated problems, and I still don't understand.
Thank you for your help.