Skip to main content
gamedev.net
🔒 Locked

reference to a reference

Started by TEUTON 2 replies 450+ views
Original Post
TEUTON
TEUTON
2 questions: 1. Why reference to a refrence is not allowed 2. I tried writing this code(refrence to a refrence), which compiles in VC6.0 successfully.

#include <iostream>
using namespace std;
int main()
{
int x;
int &p=x;
int &q=p;
return 0;
}
Sneftel
Sneftel
Quote:
Original post by TEUTON
2 questions:
1. Why reference to a refrence is not allowed
Because it would be identical to a single reference.
Quote:
2. I tried writing this code(refrence to a refrence), which compiles in VC6.0 successfully.
Because initalizing a reference with a reference causes the new reference to refer to the old reference's target.
Boder
Boder
I was going to post a new question, but it is related to this.

How can I test if two references are equal, like testing if pointers are equal?
Zakwayda
Zakwayda
Quote:
Original post by Boder
How can I test if two references are equal, like testing if pointers are equal?
Just compare addresses like you would with regular objects.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.