What is the difference between the arguments in:
int foo1(const Fred &arg) {
...
}
and
int foo2(Fred const &arg) {
...
}
?
I don’t see this case covered in the parashift FAQ.
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.
No difference as const is read right-to-left with respect to the &, so both represent a reference to an immutable Fred instance.
Fred& constwould mean the reference itself is immutable, which is redundant; when dealing with const pointers bothFred const*andFred* constare valid but different.It’s a matter of style, but I prefer using
constas a suffix since it can be applied consistently including const member functions.