前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >C++核心准则C.6:不要在一条语句内声明类或枚举值的同时又定义该类型的变量

C++核心准则C.6:不要在一条语句内声明类或枚举值的同时又定义该类型的变量

作者头像
面向对象思考
发布2020-03-25 15:53:56
7970
发布2020-03-25 15:53:56
举报

C.7: Don't define a class or enum and declare a variable of its type in the same statement

不要在一条语句内声明类或枚举类型的同时又定义该类型的变量

Reason(原因)

Mixing a type definition and the definition of another entity in the same declaration is confusing and unnecessary.

将类型和实体的定义混在一起难于理解而且没有必要。

译者注:编程不是炫技,没有必要为了减少行数而改变代码结构。

Example, bad(反面示例)
struct Data { /*...*/ } data{ /*...*/ };
Example, good(好的示例)

struct Data { /*...*/ };
Data data{ /*...*/ };

Enforcement(实施建议)
  • Flag if the } of a class or enumeration definition is not followed by a ;. The ; is missing.
  • 如果类或者枚举类型定义最后的 } 没有紧跟 ; ,或者在 ;缺失时进行提示。

原文地址:

https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c7-dont-define-a-class-or-enum-and-declare-a-variable-of-its-type-in-the-same-statement

觉得本文有帮助?请分享给更多人。

关注【面向对象思考】轻松学习每一天!

有任何疑问,欢迎留言提问或讨论。


面向对象开发,面向对象思考!

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

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

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

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

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • C.7: Don't define a class or enum and declare a variable of its type in the same statement
    • Reason(原因)
      • Example, bad(反面示例)
        • Example, good(好的示例)
          • Enforcement(实施建议)
          领券
          问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档