C++核心準則ES.21: 不要在不需要時引入變量(或常量)

ES.21: Don't introduce a variable (or constant) before you need to use it

ES.21: 不要在不需要時引入變量(或常量)

 

Reason(原因)

Readability. To limit the scope in which the variable can be used.

可讀性。爲了限定變量可用的作用域。

 

Example(示例)

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

 

Enforcement(實施建議)

Flag declarations that are distant from their first use.

標記遠離首次使用代碼的變量定義。

 

原文鏈接

https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es21-dont-introduce-a-variable-or-constant-before-you-need-to-use-it

 


 

覺得本文有幫助?歡迎點贊並分享給更多的人。

閱讀更多更新文章,請關注微信公衆號【面向對象思考】

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章