Why are pointers to a reference illegal in C++?

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 use r you 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:

int x;
int& rx = x;

int* px = ℞

In the last line, &rx takes the address of the object referred to by rx, so it’s exactly the same as if you had said &x.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)