Skip to content

Commit d1430f9

Browse files
KSroidogitbook-bot
authored andcommitted
GitBook: [#39] No subject
1 parent 3521055 commit d1430f9

4 files changed

+32
-3
lines changed

SUMMARY.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55
## 基础概念和必要语法复习 <a href="#basic" id="basic"></a>
66

7-
* [side-effect 副作用](basic/sideeffect-fu-zuo-yong.md)
8-
* [lvalue vs rvalue 左值与右值](basic/lvalue-vs-rvalue-zuo-zhi-yu-you-zhi.md)
7+
* [side-effect 副作用](sideeffect-fu-zuo-yong.md)
8+
* [lvalue vs rvalue 左值与右值](lvalue-vs-rvalue-zuo-zhi-yu-you-zhi.md)
99
* [const 常量](basic/const-chang-liang.md)

basic/const-chang-liang.md

+29
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,31 @@
11
# const 常量
22

3+
在C++中,常量一般有四种位置,为了叙述方便我临时将他们加上编号:
4+
5+
```
6+
int const0 a=0;//与 const0 int a=0 等价
7+
8+
int const1 foo(int const2 bar) const3{
9+
10+
}
11+
```
12+
13+
const0 意味着对左值`a` 的声明为一个常量,该常量的本质是只能绑定一次的定位符
14+
15+
const1意味着返回值是一个常量,这种写法在C11后逐渐变得不再推荐(这个说法是在英文互联网中搜到的),比如:
16+
17+
```
18+
const int foo() {
19+
return 3;
20+
}
21+
int main() {
22+
int x = foo(); // copies happily
23+
x = 4;// copies happily
24+
}
25+
```
26+
27+
可以正常编译并运行
28+
29+
如果你觉得const1的这种情况不好理解的话,请看上一小节最后部分中,[Mohan](https://stackoverflow.com/a/38559710/1433373)提到的例子
30+
31+
{% embed url="https://stackoverflow.com/questions/3247285/const-int-int-const" %}

basic/lvalue-vs-rvalue-zuo-zhi-yu-you-zhi.md lvalue-vs-rvalue-zuo-zhi-yu-you-zhi.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ b = std::move(tmp);
175175
176176
下面的图可能会让你更好理解他们的关系,以及为什么我在前面花费了大量篇幅讲解**表达式和左值的关系**
177177
178-
****![](../.gitbook/assets/image.png)****
178+
****![](.gitbook/assets/image.png)****
179179
180180
另外,为了让你更深刻理解,这里节选翻译一段[Mohan](https://stackoverflow.com/a/38559710/1433373) 的备忘录,他是C++早期标准的起草人之一
181181
File renamed without changes.

0 commit comments

Comments
 (0)