[EC++_item3]任何可能的時候都使用const

Things to Rember

1.Declaring something const helps compilers detect usage errors. const can be applied to objects at

any scope, to function parameters and return types, and to member functions as a whole.

將某些東西聲明爲const可幫助編譯器偵測出錯誤用法。const可被施加於任何作用域內的對象、函數參數、函數

返回類型、成員函數本體。

2.Compilers enforce bitwise constness, but you should program using conceptual constness.

編譯器強制實施bitwise constness, 但你編寫程序時應該使用“概念上的常量性”

3.When const and non-const member functions have essentially identical implementations, code

duplication can be avoided by having the non-const version call the const version.

當const和non-const成員函數有着實質等價的實現時,令non-const版本調用const版本可避免代碼重複。

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