回顾经典Effective C++ 3 4
2014-07-12 01:20
155 查看
Base of "const":
强调常量性,不可修改性。
eg:
Extend Of "const":
const 成员函数:
{
bitwise constness;编译器理念的不可修改性
logical constness;^up
}
2.对应的logical constness可修改const函数内的赋值行为:
mutable
notice-3:
当const和non-const成员函数有着实质等价,可令non-const版本调用const版本避免代码重复。
notice-4:
为免除"跨编译单元之初始化次序"问题,请以local static 对象替换non-local static 对象。
强调常量性,不可修改性。
eg:
char greeting[] = "hello"; char *p = greeting; const char*q = greeting; char* const q = greeting; const char*const q = greeting;
Extend Of "const":
const 成员函数:
{
bitwise constness;编译器理念的不可修改性
logical constness;^up
}
1.
class Ctest { public: char& operator[](std::size_t pos)const { return ptext[pos]; } private: char* ptext; }如上返回的引用可修改内部ptext,这点个人认为不好。
2.对应的logical constness可修改const函数内的赋值行为:
mutable
notice-3:
当const和non-const成员函数有着实质等价,可令non-const版本调用const版本避免代码重复。
notice-4:
为免除"跨编译单元之初始化次序"问题,请以local static 对象替换non-local static 对象。
相关文章推荐
- 回顾经典Effective C++ 2
- 回顾经典Effective C++ 9 10 11 12
- 回顾经典Effective C++ 5 6 7 8
- 回顾经典Effective C++ 1
- Effective C++回顾(5)
- (转-经典-数据段)C++回顾之static用法总结、对象的存储,作用域与生存期
- More Effective C++ 条款7
- More Effective C++ 条款16
- More effective c++ 条款10(上)
- More Effective C++ 条款21
- More Effective C++ 条款26(上)
- More Effective C++ 条款22
- More effective C++ 条款14
- More Effective C++ 条款19
- More Effective C++ 条款20
- More Effective C++ 条款6
- More effective C++ 条款13
- More effective c++ 条款10(下)
- More Effective C++ 条款24
- More Effective C++ 条款9