I'm reviewing code and which looks kind of wrong to me. I know it can be written in another way and I know it is probably useless to write it this way. Still, I was surprised that the compiler didn't generate any error/warning so I wonder if it is legal and why.
struct A
{
int val = 0;
int* GetVal() {
return &val;
}
};
void main()
{
A a;
int* const& r = a.GetVal();
}
AFAIK, a reference represents a real variable. The reference and the variable should both have the same memory address.
In this example, there is no variable holding the address (maybe a temporary?) so which variable does r refer to?
If I remove the const it doesn't compile.