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
觉得本文有帮助?请分享给更多人。
更多更新文章,欢迎关注微信公众号【面向对象思考】
面向对象设计,面向对象编程,面向对象思考!
本文来自投稿,不代表本人立场,如若转载,请注明出处:http://www.sosokankan.com/article/1384417.html
赞 (2)
打赏 微信扫一扫
马上评丨让“大灰狼”在大学无处容身
« 上一篇2019-12-11 21:09:32
非常有用!课堂教学的导入与收尾技巧(值得收藏)
下一篇 »2019-12-11 21:09:44