Where to put "&" in a parameter in a function?

Can someone tell me what is the difference between

void fun(MyClass &mc);

and

void fun(MyClass& mc);

in c ++?

+5
source share
2 answers

As indicated by none.

Initially, C allowed:

int x, *y;

Declare as int, xand a pointer to int, y.

Therefore, the part of the type definition — the bit that makes it a pointer — can be separated from the other part.

C ++ copied this wholesale.

Then the links where added, and they got a similar ad style, except &, not *. This meant that both MyClass &mc, and MyClass& mc.

By choice, when it comes to *, Strousup wrote :

"" , C ++, . , "int * p;" "int * p;"

"int * p;" "int * p;" , . ; , . ++, , .

A " C" "int * p;" "* p - , int", C ( ++) , . , * p .

" ++" "int * p;" "p int. , p int *. ++.

() :

int * p, p1;// : p1 is int *

* ​​ .

int * p, p1;// ?

- . :

int * p = & i; int p1 = p;//: int int *

, .

, - , - . , - , . . . " ++ .

, &, MyClass& mc " ++".

+8

.

C-, ++ - ish.

+5

All Articles