Very inccorrect generalization, you must admit that's actualy omitting a reference existance?
What are you talking about?
I said references behave like a value-type, of course they point to another variable, but the point is this - an operation cannot possibly aquire the address of whatever the reference is pointing to, without promoting to pointer.
All of this:
int x = 1;
int& y = x;
y += 1; // does NOT increment the address
std::cout << y;
y = 5; // does NOT set the address to 5
printf("%i", y);
Is functionally 100% equivalent to:
int x = 1;
x += 1;
std::cout << x;
x = 5;
printf("%i", x);
The reference acts as an alias to another variable. Sure its underneath value is a pointer like 0xAB6492F, but whenever you perform another operation on it, it performs the operation on the original variable, as if the reference was a pointer that has been wrapped with "(*pValue)" . If you want to get the address, you need to use &.
EDIT:
So this code hang on me for the very link link, I alter only compilation standard to first one.
Yeah, this code does not compile. First off:
SomeType myInt();
Does not create an instance of SomeType, but a SomeType (*)() function pointer. Change it to:
SomeType myInt;
Plus:
void myFirstFunction(SomeType &value)
{
std::cout << value << std::endl; // compilation error
}
I'm not going to explain why this fails. Take what I explained about references, and you should see for yourself why cout cannot print SomeType&, but can print SomeType*.