Can anybody tell me what is the difference between
void fun(MyClass &mc);
and
void fun(MyClass& mc);
in C++?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As given none.
Originally, C would allow:
To declare both an
int,xand a pointer to int,y.Hence part of the definition of the type – the bit that makes it a pointer – could be separated from another part.
C++ copied this wholesale.
Then references where added, and they got a similar style of declaration except with
&rather than*. This meant that bothMyClass &mcandMyClass& mcwere allowed.On the choice when it comes to
*, Strousup wrote:By extension, when it comes to
&,MyClass& mcmatches the “typical C++” style.