NL.26: Use conventional const notation
NL.26:使用传统的常量记法
Reason
Conventional notation is more familiar to more programmers. Consistency in large code bases.
更多的程序员熟悉常规记法。大型代码库的一致性。
Example(示例)
代码语言:javascript复制const int x = 7; // OK
int const y = 9; // bad
const int *const p = nullptr; // OK, constant pointer to constant int
int const *const p = nullptr; // bad, constant pointer to constant int
Note(注意)
We are well aware that you could claim the "bad" examples more logical than the ones marked "OK", but they also confuse more people, especially novices relying on teaching material using the far more common, conventional OK style.
我们很清楚,您可以说“不好的”示例比标记为“OK”的示例更具逻辑性,但是它们还会使更多的人感到困惑,尤其是依赖更常见,常规OK风格的教材的新手。
As ever, remember that the aim of these naming and layout rules is consistency and that aesthetics vary immensely.
与以往一样,请记住,这些命名和布局规则的目的是保持一致性,它们会带来代码外观的巨大变化。
This is a recommendation for when you have no constraints or better ideas. This rule was added after many requests for guidance.
当您没有约束或更好的选择时,可以考虑这个个建议。此规则可以在许多准则之后适用。
Enforcement(实施建议)
Flag const used as a suffix for a type.
标志const用作类型的后缀使用的情况。
原文链接
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#nl26-use-conventional-const-notation