您的位置:首页 > 编程语言 > C语言/C++

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

2014-04-06 21:26 169 查看
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版本可避免代码重复。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐