Is there a difference between the following declarations?
void somefunc(const Person &p);
void somefunc(Person const &p);
c++
Is there a difference between the following declarations?
void somefunc(const Person &p);
void somefunc(Person const &p);
Best Solution
there is no difference.
const
binds to the type to its left...unless it is the first part of the declaration in which case it binds to the right.See: https://isocpp.org/wiki/faq/const-correctness#const-ref-alt
Personally, I find that
const T &x
reads better. According to this, Bjarne also prefers to put theconst
first. Specifically because the keyword was originally going to be calledreadonly
andreadonly int x
reads better :-P.