Addison wesley effective c++ third edition 55 specific ways to improve your programs and designs

620 343 1
Addison wesley   effective c++ third edition 55 specific ways to improve your programs and designs

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Effective C++ Third Edition 55 Specific Ways to Improve Your Programs and Designs By Scott Meyers Publisher: Addison Wesley Professional Pub Date: May 12, 2005 Print ISBN: 0-321-33487-6 Pages: 320 Table of Contents | Index The first two editions of Effective C++ were embraced by hundreds of thousands of programmers worldwide The reason is clear: Scott Meyers' practical approach to C++ describes the rules of thumb used by the expertsthe things they almost always do or almost always avoid doingto produce clear, correct, efficient code.The book is organized around 55 specific guidelines, each of which describes a way to write better C++ Each is backed by concrete examples For this third edition, more than half the content is new, including added chapters on managing resources and using templates Topics from the second edition have been extensively revised to reflect modern design considerations, including exceptions, design patterns, and multithreading.Important features of Effective C++ include: Expert guidance on the design of effective classes, functions, templates, and inheritance hierarchies Applications of new "TR1" standard library functionality, along with comparisons to existing standard library components Insights into differences between C++ and other languages (e.g., Java, C#, C) that help developers from those languages assimilate "the C++ way" of doing things Effective C++ Third Edition 55 Specific Ways to Improve Your Programs and Designs By Scott Meyers Publisher: Addison Wesley Professional Pub Date: May 12, 2005 Print ISBN: 0-321-33487-6 Pages: 320 Table of Contents | Index Copyright Praise for Effective C++, Third Edition Addison-Wesley Professional Computing Series Preface Acknowledgments Introduction Terminology Chapter 1 Accustoming Yourself to C++ Item 1: View C++ as a federation of languages Item 2: Prefer consts, enums, and inlines to #defines Item 3: Use const whenever possible Item 4: Make sure that objects are initialized before they're used Chapter 2 Constructors, Destructors, and Assignment Operators Item 5: Know what functions C++ silently writes and calls Item 6: Explicitly disallow the use of compiler-generated functions you do not want Item 7: Declare destructors virtual in polymorphic base classes Item 8: Prevent exceptions from leaving destructors Item 9: Never call virtual functions during construction or destruction Item 10: Have assignment operators return a reference to *this Item 11: Handle assignment to self in operator= Item 12: Copy all parts of an object Chapter 3 Resource Management Item 13: Use objects to manage resources Item 14: Think carefully about copying behavior in resource-managing classes Item 15: Provide access to raw resources in resource-managing classes Item 16: Use the same form in corresponding uses of new and delete Item 17: Store newed objects in smart pointers in standalone statements Chapter 4 Designs and Declarations Item 18: Make interfaces easy to use correctly and hard to use incorrectly Item 19: Treat class design as type design Item 20: Prefer pass-by-reference-to-const to pass-by-value Item 21: Don't try to return a reference when you must return an object Item 22: Declare data members private Item 23: Prefer non-member non-friend functions to member functions Item 24: Declare non-member functions when type conversions should apply to all parameters Item 25: Consider support for a non-throwing swap Chapter 5 Implementations Item 26: Postpone variable definitions as long as possible Item 27: Minimize casting Item 28: Avoid returning "handles" to object internals Item29: Strive for exception-safe code Item 30: Understand the ins and outs of inlining Item31: Minimize compilation dependencies between files Chapter 6 Inheritance and Object-Oriented Design Item 32: Make sure public inheritance models "is-a." Item 33: Avoid hiding inherited names Item 34: Differentiate between inheritance of interface and inheritance of implementation Item 35: Consider alternatives to virtual functions Item 36: Never redefine an inherited non-virtual function Item 37: Never redefine a function's inherited default parameter value Item 38: Model "has-a" or "is-implemented-in-terms-of" through composition Item 39: Use private inheritance judiciously Item 40: Use multiple inheritance judiciously Chapter 7 Templates and Generic Programming Item 41: Understand implicit interfaces and compile-time polymorphism Item 42: Understand the two meanings of typename Item 43: Know how to access names in templatized base classes Item 44: Factor parameter-independent code out of templates Item 45: Use member function templates to accept "all compatible types." Item 46: Define non-member functions inside templates when type conversions are desired Item 47: Use traits classes for information about types Item 48: Be aware of template metaprogramming Chapter 8 Customizing new and delete Item 49: Understand the behavior of the new-handler Item 50: Understand when it makes sense to replace new and delete Item 51: Adhere to convention when writing new and delete Item 52: Write placement delete if you write placement new Chapter 9 Miscellany Item 53: Pay attention to compiler warnings Item 54: Familiarize yourself with the standard library, including TR1 Item.55: Familiarize yourself with Boost Appendix A Beyond Effective C++ Appendix B Item Mappings Between Second and Third Editions Index Copyright Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals The author and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein The publisher offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales, which may include electronic versions and/or custom covers and content particular to your business, training goals, marketing focus, and branding interests For more information, please contact: U.S Corporate and Government Sales (800) 382-3419 corpsales@pearsontechgroup.com For sales outside the U.S., please contact: International Sales international@pearsoned.com This Book Is Safari Enabled The Safari® Enabled icon on the cover of your favorite technology book means the book is available through Safari Bookshelf When you buy this book, you get free access to the online edition for 45 days Safari Bookshelf is an electronic reference library that lets you easily search thousands of technical books, find code samples, download chapters, and access technical information whenever and wherever you need it To gain 45-day Safari Enabled access to this book: Go to http://www.awprofessional.com/safarienabled Complete the brief registration form Enter the coupon code AAAA-AAAA-AAAA-AAAA-AAAA If you have difficulty registering on Safari Bookshelf or accessing the online edition, please e-mail customer-service@safaribooksonline.com Visit us on the Web: www.awprofessional.com Library of Congress Control Number: 2005010101 Copyright © 2005 Pearson Education, Inc All rights reserved Printed in the United States of America This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise For information regarding permissions, write to: Pearson Education, Inc Rights and Contracts Department One Lake Street Upper Saddle River, NJ 07458 Text printed in the United States on recycled paper at Courier in Westford, Massachusetts.First printing, May 2005 Dedication For Nancy, without whom nothing would be much worth doing Wisdom and beauty form a very rare combination Petronius Arbiter Satyricon, XCIV Dedication And in memory of Persephone, 19952004 Praise for Effective C++, Third Edition "Scott Meyers' book, Effective C++, Third Edition, is distilled programming experience experience that you would otherwise have to learn the hard way This book is a great resource that I recommend to everybody who writes C++ professionally." Peter Dulimov, ME, ngineer, Ranges and Assessing Unit, NAVSYSCOM, Australia "The third edition is still the best book on how to put all of the pieces of C++ together in an efficient, cohesive manner If you claim to be a C++ programmer, you must read this book." Eric Nagler, Consultant, Instructor, and author of Learning C++ "The first edition of this book ranks among the small (very small) number of books that I credit with significantly elevating my skills as a 'professional' software devel-oper Like the others, it was practical and easy to read, but loaded with important advice Effective C++, Third Edition, continues that tradition C++ is a very powerful programming language If C gives you enough rope to hang yourself, C++ is a hard-ware store with lots of helpful people ready to tie knots for you Mastering the points discussed in this book will definitely increase your ability to effectively use C++ and reduce your stress level." Jack W Reeves, Chief Executive Officer, Bleading Edge Software Technologies "Every new developer joining my team has one assignment to read this book." Michael Lanzetta, Senior Software Engineer "I read the first edition of Effective C++ about nine years ago, and it immediately became my favorite book on C++ In my opinion, Effective C++, Third Edition, remains a must-read today for anyone who wishes to program effectively in C++ We would live in a better world if C++ programmers had to read this book before writing their first line of professional C++ code." Danny Rabbani, Software Development Engineer "I encountered the first edition of Scott Meyers' Effective C++ as a struggling programmer in the trenches, trying to get better at what I was doing What a lifesaver! I found Meyers' advice was practical, useful, and effective, fulfilling the promise of the title 100 percent The third edition brings the practical realities of using C++ in serious development projects right up to date, adding chapters on the language's very latest issues and features I was delighted to still find myself learning something interesting and new from the latest edition of a book I already thought I knew well." Michael Topic, Technical Program Manager "From Scott Meyers, the guru of C++, this is the definitive guide for anyone who wants to use C++ safely and effectively, or is transitioning from any other OO language to C++ This book has valuable information presented in a clear, concise, entertaining, and insightful manner." Siddhartha Karan Singh, Software Developer "This should be the second book on C++ that any developer should read, after a general introductory text It goes beyond the how and what of C++ to address the why and wherefore It helped me go from knowing the syntax to understanding the philosophy of C++ programming." Timothy Knox, Software Developer "This is a fantastic update of a classic C++ text Meyers covers a lot of new ground in this volume, and every serious C++ programmer should have a copy of this new edition." Jeffrey Somers, Game Programmer "Effective C++, Third Edition, covers the things you should be doing when writing code and does a terrific job of explaining why those things are important Think of it as best practices for writing C++." Jeff Scherpelz, Software Development Engineer "As C++ embraces change, Scott Meyers' Effective C++, Third Edition, soars to remain in perfect lock-step with the language There are many fine introductory books on C++, but exactly one second book stands head and shoulders above the rest, and you're holding it With Scott guiding the way, prepare to do some soaring of your own!" Leor Zolman, C++ Trainer and Pundit, BD Software "This book is a must-have for both C++ veterans and newbies After you have finished reading it, it will not collect dust on your bookshelf you will refer to it all the time." Sam Lee, Software Developer "Reading this book transforms ordinary C++ programmers into expert C++ programmers, step-by-step, using 55 easy-to-read items, each describing one technique or tip." Jeffrey D Oldham, Ph.D., Software Engineer, Google "Scott Meyers' Effective C++ books have long been required reading for new and experienced C++ programmers alike This new edition, incorporating almost a decade's worth of C++ language development, is his most content-packed book yet He does not merely describe the problems inherent in the language, but instead he provides unambiguous and easy-tofollow advice on how to avoid the pitfalls and write 'effective C++.' I expect every C++ programmer to have read it." Philipp K Janert, Ph.D., Software Development Manager "Each previous edition of Effective C++ has been the must-have book for developers who have used C++ for a few months or a few years, long Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [R] [S] [T] [U] [V] [W] [X] [Z] Saks, Dan Santos, Eugene, Jr Satch Satyricon Scherpelz, Jeff Schirripa, Steve Schober, Hendrik 2nd 3rd Schroeder, Sandra scoped_array 2nd 3rd scopes, inheritance and sealed classes, in C# sealed methods, in C# second edition [See 2nd edition] self-assignment, operator= and 2nd set set_new_handler class-specific, implementing using 2nd set_unexpected function shadowing, names [See name shadowing] Shakespeare, William shared memory, placing objects in shared_array shared_ptr implementation in Boost, costs sharing code [See duplication, duplication;avoiding] sharing common features Shewchuk, John side effects, exception safety and signatures definition of explicit interfaces and simple virtual functions, meaning of Singh, Siddhartha Singleton pattern size_t sizeof 2nd empty classes and freestanding classes and sizes of freestanding classes of objects sleeping pills slist Smallberg, David 2nd 3rd Smalltalk smart pointers 2nd 3rd 4th 5th 6th 7th aaa] [See also std::auto_ptr and tr1::shared_ptr[smart pointers] get and in Boost 2nd 3rd web page for in TR1 newed objects and 2nd type conversions and 2nd Socrates Some Must Watch While Some Must Sleep Somers, Jeff specialization invariants over partial, of std::swap total, of std::swap 2nd specification [See interfaces] SquareMatrix name hiding example squares and rectangles 2nd standard exception hierarchy standard forms of operator new/delete standard library [See C++ standard library, C standard library] standard template library [See STL] Stasko, John statements using new, smart pointers and 2nd static binding of default parameters of non-virtual functions objects, returning references to 2nd type, definition of static functions, ctors and dtors and static members const member functions and definition initialization static objects definition of multithreading and static_cast 2nd 3rd 4th 5th 6th aaa] [See also casting[static_cast] std namespace, specializing templates in std::auto_ptr 2nd 3rd conversion to tr1::shared_ptr and delete [i] and pass by const and std::auto_ptr, deleter support and std::char_traits std::iterator_traits, pointers and std::list std::max, implementation of std::numeric_limits std::set 2nd std::size_t std::swap aaa] [See also swap[std::swap] implementation of overloading partial specialization of total specialization of 2nd std::tr1 [See TR1] stepping through functions, inlining and STL allocators as sublanguage of C++ containers, swap and definition of iterator categories in 2nd Strategy pattern 2nd string and text utilities, in Boost strong guarantee, the Stroustrup, Bjarne 2nd Stroustrup, Nicholas 2nd Sutter, Herb 2nd 3rd 4th 5th 6th swallowing exceptions swap aaa] [See also std::swap[swap] calling exceptions and STL containers and when to write symbols, available in both C and C++ Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [R] [S] [T] [U] [V] [W] [X] [Z] template metaprogramming efficiency and hello world in pattern implementations and support in Boost support in TR1 Template Method pattern templates code bloat, avoiding in 2nd combining with inheritance defining errors, when detected expression headers and in std, specializing inlining and instantiation of member functions 2nd names in base classes and 2nd non-type parameters parameters, omitting pointer type parameters and shorthand for specializations 2nd partial 2nd total 2nd 3rd type conversions and 2nd type deduction for 2nd temporary objects, eliminated by compilers terminology, used in this book 2nd testing and correctness, Boost support for text and string utilities, in Boost third edition [See 3rd edition] this->, to force base class lookup 2nd threading [See multithreading] Tilly, Barbara TMP [See template metaprogramming] Tondo, Clovis Topic, Michael total class template specialization total specialization of std::swap 2nd total template specializations TR1 2nd 3rd array component bind component Boost and 2nd 3rd 4th boost as synonym for std::tr1 C99 compatibility component function component hash tables component math functions component mem_fn component random numbers component reference_wrapper component regular expression component result_of component smart pointers component support for TMP tuples component type traits component tr1::array tr1::bind 2nd tr1::function 2nd 3rd tr1::mem_fn tr1::reference_wrapper tr1::result_of tr1::shared_ptr 2nd 3rd 4th 5th construction from other smart pointers and cross-DLL problem and delete [i] and deleter support in 2nd 3rd member template ctors in 2nd tr1::tuple tr1::unordered_map 2nd tr1::unordered_multimap tr1::unordered_multiset tr1::unordered_set tr1::weak_ptr traits classes 2nd transfer, ownership translation unit, definition of Trux, Antoine Tsao, Mike tuples, in TR1 type conversions 2nd explicit ctors and implicit implicit vs explicit 2nd non-member functions and 2nd 3rd 4th private inheritance and smart pointers and 2nd templates and 2nd type deduction, for templates 2nd type design 2nd type traits, in TR1 typedef, typename and 2nd typedefs, new/delete and typeid 2nd 3rd 4th typelists typename 2nd compiler variations and typedef and 2nd vs class types built-in, initialization 2nd compatible, accepting all 2nd if else for integral, definition of traits classes and 2nd Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [R] [S] [T] [U] [V] [W] [X] [Z] undeclared interface undefined behavior advance and array deletion and augmenting the std namespace casting + pointer arithmetic and definition of destroyed objects and exceptions and initialization order and invalid array index and multiple deletes and 2nd null pointers and object deletion and 2nd 3rd uninitialized values and undefined values of members before construction and after destruction unexpected function uninitialized data members, virtual functions and values, reading unnecessary objects, avoiding unused objects cost of exceptions and Urbano, Nancy L 2nd 3rd 4th [See also goddess] URLs Effective C++ errata list Boost 2nd 3rd Boost smart pointers Greg Comeau's C/C++ FAQ Scott Meyers' mailing list Scott Meyers' web site this book's errata list usage statistics, memory management and using declarations name hiding and name lookup and Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [R] [S] [T] [U] [V] [W] [X] [Z] valarray value, pass by [See pass-by-value] Van Wyk, Chris 2nd Vandevoorde, David variable, vs object variables definitions, postponing 2nd vector template Viciana, Paco virtual base classes virtual constructors 2nd virtual destructors operator delete and polymorphic base classes and 2nd virtual functions alternatives to 2nd ctors/dtors and 2nd default implementations and 2nd default parameters and 2nd dynamic binding of efficiency and explict base class qualification and implementation 2nd inlining and language interoperability and meaning of none in class preventing overrides private pure [See pure virtual functions] simple, meaning of uninitialized data members and virtual inheritance [See inheritance] virtual table virtual table pointer Vlissides, John vptr vtbl Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [R] [S] [T] [U] [V] [W] [X] [Z] Wait, John 2nd warnings, from compiler 2nd calls to virtuals and inlining and partial copies and Widget class, as used in this book Widget mem funcs using rhs Wiegers, Karl Wilson, Matthew Wizard of Oz, allusion to Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [R] [S] [T] [U] [V] [W] [X] [Z] XP, allusion to XYZ Airlines Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [R] [S] [T] [U] [V] [W] [X] [Z] Zabluda, Oleg Zolman, Leor 2nd 3rd ... John Lakos, Large-Scale C++ Software Design Scott Meyers, Effective C++ CD: 85 Specific Ways to Improve Your Programs and Designs Scott Meyers, Effective C++, Third Edition: 55 Specific Ways to Improve Your Programs and Designs. .. Scott Meyers, Effective C++, Third Edition: 55 Specific Ways to Improve Your Programs and Designs Scott Meyers, More Effective C++: 35 New Ways to Improve Your Programs and Designs Scott Meyers, Effective STL: 50 Specific Ways to Improve Your Use of the Standard Template Library.. .Effective C++ Third Edition 55 Specific Ways to Improve Your Programs and Designs By Scott Meyers Publisher: Addison Wesley Professional Pub Date: May 12, 2005

Ngày đăng: 25/03/2019, 17:13

Từ khóa liên quan

Mục lục

  • Effective C++ Third Edition 55 Specific Ways to Improve Your Programs and Designs

  • Table of Contents

  • Copyright

  • Praise for Effective C++, Third Edition

  • Addison-Wesley Professional Computing Series

  • Preface

  • Acknowledgments

  • Introduction

    • Terminology

    • Chapter 1. Accustoming Yourself to C++

      • Item 1: View C++ as a federation of languages

      • Item 2: Prefer consts, enums, and inlines to #defines

      • Item 3: Use const whenever possible

      • Item 4: Make sure that objects are initialized before they're used

      • Chapter 2. Constructors, Destructors, and Assignment Operators

        • Item 5: Know what functions C++ silently writes and calls

        • Item 6: Explicitly disallow the use of compiler-generated functions you do not want

        • Item 7: Declare destructors virtual in polymorphic base classes

        • Item 8: Prevent exceptions from leaving destructors

        • Item 9: Never call virtual functions during construction or destruction

        • Item 10: Have assignment operators return a reference to *this

        • Item 11: Handle assignment to self in operator=

        • Item 12: Copy all parts of an object

Tài liệu cùng người dùng

Tài liệu liên quan