The function follows the link.

Recently, an expert from C ++ told me that:

void f(int &*r); 

- a valid pass by reference example, although I thought it was some kind of pointer to a link that is illegal. As far as I know, the correct form for passing by reference is either a form of the following:

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

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

+6
source share
2 answers

The first (pointer to link) is illegal in all versions of C ++. The remaining two are legal .

Leader: Ignore your instructor - he / she does not know C ++, at least in this case.

+8
source

Is not allowed,

from C ++ Standard 8.3.2 / 5:

There should be no links to links, no arrays of links, and no pointers to links .

and also does not compile, g ++ outputs:

error: cannot declare a pointer to 'int &'

+3
source

All Articles