Consider the following:
int someA = 1;
int someB = 2;
int &a = someA;
int &b = someB;
a = b; // what happens here?
What’s happening here with the references? Just curious.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Having two reference variables equal to each other is in itself not an error. It may be confusing. However, what your code does is not setting a reference to another reference, it’s altering the value of
_Afrom1to2, which is what’s in_B.You can ONLY set a reference ONCE [where it is initialized]. Once it’s been initialized, it will simply become an alias for the original variable.
You could do this:
and
would store the value
1into_A, which already has the value1.