前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >C++核心准则​NL.26:使用传统的常量记法

C++核心准则​NL.26:使用传统的常量记法

作者头像
面向对象思考
发布2020-12-15 15:02:13
5360
发布2020-12-15 15:02:13
举报

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

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2020-12-05,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 面向对象思考 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • NL.26: Use conventional const notation
  • Reason
    • Note(注意)
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档