条款34将文件间的编译依赖性降至最低(Clause 34 minimize dependency on compilation between files).docVIP

条款34将文件间的编译依赖性降至最低(Clause 34 minimize dependency on compilation between files).doc

  1. 1、本文档共19页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
  5. 5、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
  6. 6、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们
  7. 7、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
  8. 8、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
条款34将文件间的编译依赖性降至最低(Clause 34 minimize dependency on compilation between files)

条款34将文件间的编译依赖性降至最低(Clause 34 minimize dependency on compilation between files) Clause 34: minimizes the dependency on compilation between files Suppose you open your C++ program code one day and then make minor changes to the implementation of a class. Remind you that the change is not the interface, but the implementation of the class, that is, the details. Then you are ready to regenerate the program, thinking that the compilation and linking should take only a few seconds. After all, its just a class changed! So you clicked on Rebuild or entered make (or something like that). Yet what awaits you is astonishment, followed by pain. Because you find that the whole world is being recompiled and re linked! When all this happens, are you just angry? The reason for the problem is that C++ isnt doing very well in separating interfaces from implementation. In particular, the class definition of C++ contains not only interface specifications, but also many implementation details. Such as: Class Person { Public: Person (const, string, name, const, Date, birthday), Const, Address, addr, const, Country, country); Virtual, ~Person (); ... / / simplicity, omit the copy constructor / / function and assignment operator function String name () const; String birthDate () const; String address () const; String nationality () const; Private: String name_; / / implementation details date birthdate _; / / 实现细节 address address _; / / 实现细节 the country is _; / / 实现细节 }; 这很难称得上是一个很高明的设计, 虽然它展示了一种很有趣的命名方式: 当私有数据和公有函数都想用某个名字来标识时, 让前者带一个尾部下划线就可以区别了.这里要注意到的重要一点是, person的实现用到了一些类, 即string, date, address和country; person要想被编译, 就得让编译器能够访问得到这些类的定义.这样的定义一般是通过 # include指令来提供的, 所以在定义person类的文件头部, 可以看到象下面这样的语句. # include string / 用于string类型 (参见条款49) # include date.h # include address.h # include country.h 遗憾的是, 这样一来, 定义person的文件和这些头文件之间就建立了编译依赖关系.所以如果任一个辅助类 (即string, date, address和country) 改变了它的实现, 或任一个辅助类所依赖的类改变了实现, 包含person类的文件以及任何使用了person类的文件就必须重新编译.对于person类的用户来说, 这实在是令人讨厌, 因为这种情况用户绝对是束手无策. 那么.

文档评论(0)

f8r9t5c + 关注
实名认证
文档贡献者

该用户很懒,什么也没介绍

版权声明书
用户编号:8000054077000003

1亿VIP精品文档

相关文档