28 March 2023

C++ 核心指南目录

“Don’t introduce a variable (or constant) before you need to use it”

理由

可读性。限制变量能使用的范围。

例如(坏例子)

int x = 7;
// ... no use of x here ...
++x;

强化

标记变量第一次使用的位置与声明的位置距离很远的情况