Effective C++ 读书笔记2

Item 25
Avoid returning handles(references, pointers, or iterators) to object internals. It increases encapsulation, helps const member functions act const, and minimizes the creation of dangling handles.

Item 26
1. Functions offering the basic guarantee promise that if an exception is thrown, everything in the program remains in a valid state.
2. Functions offering the strong guarantee promise that if an exception is thrown, the state of the program is unchanged.
3. Functions offering the nothrow guarantee promise never to throw exceptions, because they always do what they promise to do.

  • Exception-safe functions leak no resources and allow no data structures to become corrupted, even when exceptions are thrown. Such functions offer the basi, strong, or nothrow guarantees.
  • The strong guarantee can often be implemented via copy-and-swap,but the strong guarantee is not practical for all functions.
  • A function can usually offer a guarantee no stronger than the weakest guarantee of the functions it calls.

Item 27
1. Limit most inlining to small, frequently called functions. This facilitates debugging and binary upgradability, minimizes potential code bloat, and maximizes the chances of greater program speed.
2. Don’t declare function templates inline just because they appear in header files.

Item 28
1. The general idea behind minimizing compilation dependencies is to depend on declarations instead of definitions. Two approached based on this idea are Handle classed and Interface classed.
2. Library header files should exist in full and declaration-only forms. This applies regardless of whether templates are involved.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值