Skip to content

Commit f5cbb02

Browse files
authored
Apply suggestions from code review
1 parent 253c77f commit f5cbb02

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

docs/functions.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ auto f() {
6565
void f() {
6666
std::println("hello");
6767
}
68+
69+
// 值得注意的是,返回类型用 `auto` 来推导的函数,如果有多条 `return` 语句,那么他们必须是相同的类型;否则报错
70+
auto f(int x) {
71+
if (x > 0) {
72+
return 1; // int
73+
} else {
74+
return 3.14; // double
75+
}
76+
} // 错误:有歧义,无法确定 auto 应该推导为 int 还是 double
6877
```
6978
7079
<!-- decltype(auto)... -->

0 commit comments

Comments
 (0)