declare references to references works!
Hi!
You cannot declare references at references (eg. int& &rr = r), but this way, it works:
„_int main(void)
„_{
„_ int a = 1;
„_ int &r = a;
„_ int &rr = r;
| rr++;
| cout << a; // output: 2!
|
|}
Why does this work!?
Depends it which compiler you are using?
regards,
Manuel
Re: declare references to references works!
Quote:
Originally posted by ManuelH
Hi!
You cannot declare references at references (eg. int& &rr = r), but this way, it works:
„_int main(void)
„_{
„_ int a = 1;
„_ int &r = a;
„_ int &rr = r;
| rr++;
| cout << a; // output: 2!
|
|}
Why does this work!?
Depends it which compiler you are using?
regards,
Manuel
That's because you're not referencing a reference. You're just referencing the variable a again.
Just an added information
Every time you are trying to perform any operation with a reference, "Despite appearances, no operator operates on a reference. The reference always refers to the object it was initialized with".
Which just means that when ever you are trying to take a reference to (reference to an object), you are just taking reference to the object