Guru of the Week 条款07:编译期的依赖性

Guru of the Week 条款07:编译期的依赖性

难度:7 / 10

(大多数程序员使用#include包含的头文件都比实际需要的多。你也是这样的吗?想知道的话,请看本条款。)

[问题]

[注意:这个问题比想象的还要难!下面程序中的注释都是非常有用的。]

大多数程序员使用#include包含的头文件都比实际需要的要多。这会严重的影响并延长程序的建立时间(build time),特别是当一个被频繁使用的头文件中包含了太多其它的头文件的时候,问题越发严重。
Qt tutorial中第7章提到了这个问题

 class QSlider;

This is another classic trick, but one that's much less used often. Because we don't need QSlider in the interface of the class, only in the implementation, we use a forward declaration of the class in the header file and include the header file for QSlider in the .cpp file.

接口与实现是要分开的,这一点要注意。稍不小心,就会让面向对象带来的好处,瞬间被“雪崩”埋没了。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值