Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c++ pointer to a reference

Tags:

c++

Is it legal to have a pointer of a reference in C++?

For example:

int &ref = array[idx];
func(&ref);

One reason I can think of why you might want to do this if func() already exists in a library which you can't change.

like image 794
Himadri Choudhury Avatar asked Mar 21 '11 00:03

Himadri Choudhury


1 Answers

It is not. The address of a reference can be taken, but "pointer to a reference of T" is not a valid type. What you are doing here is taking a pointer to the object itself, since a reference to an object simply creates another name by which you can access that same object.

like image 106
Jon Avatar answered Sep 23 '22 20:09

Jon