![]()
内容推荐 有人说C++程序员可以分为两类,读过Effective C++的和没读过的。世界顶级C++大师Scott Meyers成名之作的第三版的确当得起这样的评价。当您读过这本书之后,就获得了迅速提升自己C++功力的一个契机。 在国际上,本书所引起的反响,波及整个计算机技术的出版领域,余音至今未绝。几乎在所有C++书籍的推荐名单上,本书都会位于前三名。作者高超的技术把握力、独特的视角、诙谐轻松的写作风格、独具匠心的内容组织,都受到极大的推崇和仿效。这种奇特的现象,只能解释为人们对这本书衷心的赞美和推崇。 这本书不是读完一遍就可以束之高阁的快餐读物,也不是用以解决手边问题的参考手册,而是需要您去反复阅读体会的,C++是真正程序员的语言,背后有着精深的思想与无以伦比的表达能力,这使得它具有类似宗教般的魅力。希望这本书能够帮您跨越C++的重重险阻,领略高处才有的壮美风光,做一个成功而快乐的C++程序员。 作者简介 梅耶(Scot Meyers),是C++领域公认的权威,并对全球客户提供咨询服务。他是《Effective C++》的作者,《C++Repon》的知名专栏作家,全球各技术研讨会上极具号召力的讲师。他于1993年获得布朗大学(Brown University)的计算机科学博土学位。 目录 译序 中英简繁术语对照 目录 序言 致谢 导读 1.让自己习惯C++ Accustoming Yourself to C++ 条款01:视C++ 为一个语言联邦 View C++ as a federation of languages 条款02:尽量以const, enum, inline替换#define Prefer consts,enums, and inlines to #defines 条款03:尽可能使用const Use const whenever possible 条款04:确定对象被使用前已先被初始化 Make sure that objects are initialized before they're used 2.构造/析构/赋值运算 Constructors, Destructors, and Assignment Operators 条款05:了解C++ 默默编写并调用哪些函数 Know what functions C++ silently writes and calls 条款06:若不想使用编译器自动生成的函数,就该明确拒绝 Explicitly disallow the use of compiler-generated functions you do not want 条款07:为多态基类声明virtual析构函数 Declare destructors virtual in polymorphic base classes 条款08:别让异常逃离析构函数 Prevent exceptions from leaving destructors 条款09:绝不在构造和析构过程中调用virtual函数 Never call virtual functions during construction or destruction 条款10:令operator=返回一个reference to *this Have assignment operators return a reference to *this 条款11:在operator=中处理“自我赋值” Handle assignment to self in operator 条款12:复制对象时勿忘其每一个成分 Copy all parts of an object 3.资源管理 Resource Management 条款13:以对象管理资源 Use objects to manage resources 条款14:在资源管理类中小心copying行为 Think carefully about copying behavior in resource-managing classes 条款15:在资源管理类中提供对原始资源的访问 Provide access to raw resources in resource-managing classes 条款16:成对使用new和delete时要采取相同形式 Use the same form in corresponding uses of new and delete 条款17:以独立语句将newed对象置入智能指针 Store newed objects in smart pointers in standalone statements 4.设计与声明 Designs and Declarations 条款18:让接口容易被正确使用,不易被误用 Make interfaces easy to use correctly and hard to use incorrectly 条款19:设计class犹如设计type Treat class design as type design 条款20:宁以pass-by-reference-to-const替换pass-by-value Prefer pass-by-reference-to-const to pass-by-value 条款21:必须返回对象时,别妄想返回其reference Don't try to return a reference when you must return an object 条款22:将成员变量声明为private Declare data members private 条款23:宁以non-member、non-friend替换member函数 Prefer non-member non-friend functions to member functions 条款24:若所有参数皆需类型转换,请为此采用non-member函数 Declare non-member functions when type conversions should apply to all parameters 条款25:考虑写出一个不抛异常的swap函数 Consider support for a non-throwing swap 5.实现 Implementations 条款26:尽可能延后变量定义式的出现时间 Postpone variable definitions as long as possible 条款27:尽量少做转型动作 Minimize casting 条款28:避免返回handles指向对象内部成分 Avoid returning "handles" to object internals 条款29:为“异常安全”而努力是值得的 Strive for exception-safe code 条款30:透彻了解inlining的里里外外 Understand the ins and outs of inlining 条款31:将文件间的编译依存关系降至最低 Minimize compilation dependencies between files 6.继承与面向对象设计 Inheritance and Object-Oriented Design 条款32:确定你的public继承塑模出is-a关系 Make sure public inheritance models "is-a." 条款33:避免遮掩继承而来的名称 Avoid hiding inherited names 条款34:区分接口继承和实现继承 Differentiate between inheritance of interface and inheritance of implementation 条款35:考虑virtual函数以外的其他选择 Consider alternatives to virtual functions 条款36:绝不重新定义继承而来的non-virtual函数 Never redefine an inherited non-virtual function 条款37:绝不重新定义继承而来的缺省参数值 Never redefine a function's inherited default parameter value 条款38:通过复合塑模出has-a或“根据某物实现出” Model "has-a" or "is-implemented-in-terms-of" through composition 条款39:明智而审慎地使用private继承 Use private inhe |