5
votes

Recently a c++ expert told me that :

void f(int &*r);

is a valid pass by reference example although I thought this is some kind of pointer to a reference which is illegal. From my knowledge the correct form for pass by reference is either form of the following:

void f1(int *&r);
void f2(int &r);

Can you explain the situation of the first example (function f)?

2
Your "expert" was confused. - juanchopanza
Im not sure but int* &r its a reference to a pointer, int &r int s reference to an int, never seen int &*r... - Netwave
Did that person tell you that they were an expert, or did you assign the role to them yourself? - Lightness Races in Orbit
He is considered expert by the company he works for - dragosb

2 Answers

8
votes

The first one (pointer to reference) is illegal in all versions of C++. The rest two are legal.

The bottomline : Ignore Your Instructor — he/she doesn't know C++, at least in this case.

3
votes

Its not allowed,

from C++ Standard 8.3.2/5:

There shall be no references to references, no arrays of references, and no pointers to references.

and also it does not compile, g++ outputs:

error: cannot declare pointer to 'int&'