Unverified Commit 2ca796d5 authored by Nano's avatar Nano Committed by GitHub
Browse files

Merge pull request #2657 from zhb2000/patch-1

Fix a typo
parents 319c3886 da4bf8d1
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -193,14 +193,14 @@ int main() {
 `constexpr` 说明符声明可以在编译时求得函数或变量的值。其与 `const` 的主要区别是一定会在编译时进行初始化。用于对象声明的 `constexpr` 说明符蕴含 `const` ,用于函数声明的 `constexpr` 蕴含 `inline` 。来看一个例子

```cpp
int frac(int x) { return x ? x * frac(x - 1) : 1; }
int fact(int x) { return x ? x * fact(x - 1) : 1; }
int main() {
  constexpr int a = frac(5);  // ERROR: 函数调用在常量表达式中必须具有常量值
  constexpr int a = fact(5);  // ERROR: 函数调用在常量表达式中必须具有常量值
  return 0;
}
```

`int frac(int x)` 之前加上 `constexpr` 则编译通过。
`int fact(int x)` 之前加上 `constexpr` 则编译通过。

## std::tuple