参数之间有什么区别:
int foo1(const Fred &arg) {
...
}
Run Code Online (Sandbox Code Playgroud)
和
int foo2(Fred const &arg) {
...
}
Run Code Online (Sandbox Code Playgroud)
?我没有看到parashift FAQ中涉及的这个案例.
我知道通过引用传递和传递指针的主题被大量覆盖...我很清楚我理解所有的细微差别,直到我读到这个:
http://carlo17.home.xs4all.nl/cpp/const.qualifier.html
读取(如果链接死亡)
The prototype for foobar can have any of the following footprints:
void foobar(TYPE); // Pass by value
void foobar(TYPE&); // Pass by reference
void foobar(TYPE const&); // Pass by const reference
Note that I put the const to the right of TYPE because we don't know if TYPE (this is not a template parameter, but rather for instance a literal char*) is a pointer or not!
Run Code Online (Sandbox Code Playgroud)
作者的意思是"注意我把const放在TYPE的右边,因为我们不知道TYPE ......是否是一个指针!"
我在这个主题上读过的所有内容都一致地说:
void foodbar(TYPE const&)
也是等同的
void foobar(const TYPE&)
如果我理解正确的作者,他/她说的是: …