Why does the initialisation of C++ references works without the "adress-of" operator (which is &)?
Isn't the assignment of Object with a type A
to a reference with a type A&
wrong?
Shouldn't the assignment use the "&" operator on the right side?
int var = 2
int& ref = var //why can we assign var of type 'int' to ref of type 'int&'?
int& ref = &var //shouldn't it be like that, so that we will assign the ADRESS to the reference?
EDIT: To summarize it:
- References are alternative names for Objects.
- The type of References is created by appending '&' to the type of the referenced object.
- References are the same as the references object in every context.
- They do not store the memory of the object as pointers do, the presence of the 'adress-of' operator '&' was misleading here.