As the title itself mentions – why are pointer to a reference illegal, while the reverse is legal in C++?
Share
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.
A pointer needs to point to an object. A reference is not an object.
If you have a reference
r, once it is initialized, any time you useryou are actually using the object to which the reference refers.Because of this, you can’t take the address of a reference to be able to get a pointer to it in the first place. Consider the following code:
In the last line,
&rxtakes the address of the object referred to byrx, so it’s exactly the same as if you had said&x.