相关疑难解决方法(0)

C++:const引用,在类型说明符之后

参数之间有什么区别:

int foo1(const Fred &arg) {
...
}
Run Code Online (Sandbox Code Playgroud)

int foo2(Fred const &arg) {
...
}
Run Code Online (Sandbox Code Playgroud)

?我没有看到parashift FAQ中涉及的这个案例.

c++ const reference

132
推荐指数
5
解决办法
7万
查看次数

C++ Pass by const引用语法

我知道通过引用传递和传递指针的主题被大量覆盖...我很清楚我理解所有的细微差别,直到我读到这个:

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&)

如果我理解正确的作者,他/她说的是: …

c++ syntax reference

7
推荐指数
1
解决办法
3751
查看次数

标签 统计

c++ ×2

reference ×2

const ×1

syntax ×1