ebook img

More Effective C++ PDF

335 Pages·1.833 MB·English
by  MeyersScott
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview More Effective C++

Praise for More Effective C++: 35 New Ways to Improve Your Programs and Designs “This is an enlightening book on many aspects of C++: both the regions of the language you seldom visit, and the familiar ones you THOUGHT you understood. Only by understanding deeply how the C++ compiler interprets your code can you hope to write robust software using this language. This book is an invaluable resource for gaining that level of understanding. After reading this book, I feel like I've been through a code review with a master C++ programmer, and picked up many of his most valuable insights.” — Fred Wild, Vice President of Technology, Advantage Software Technologies “This book includes a great collection of important techniques for writing programs that use C++ well. It explains how to design and implement the ideas, and what hidden pitfalls lurk in some obvious alternative designs. It also includes clear explanations of features recently added to C++. Anyone who wants to use these new features will want a copy of this book close at hand for ready reference.” — Christopher J. Van Wyk, Professor, Mathematics and Computer Science, Drew University “Industrial strength C++ at its best. The perfect companion to those who have read Effective C++.” — Eric Nagler, C++ Instructor and Author, University of California Santa Cruz Extension “More Effective C++ is a thorough and valuable follow-up to Scott's first book, Effective C++. I believe that every professional C++ developer should read and commit to memory the tips in both Effective C++ and More Effective C++. I've found that the tips cover poorly understood, yet important and sometimes arcane facets of the language. I strongly recommend this book, along with his first, to developers, testers, and managers ... everyone can benefit from his expert knowledge and excellent presentation.” — Steve Burkett, Software Consultant This page intentionally left blank More Effective C++ Addison-Wesley Professional Computing Series Brian W. Kernighan, Consulting Editor Matthew H. Austern, Generic Programming and the STL:Using and Extending the C++Standard Template Library David R. Butenhof, Programming with POSIX®Threads Brent Callaghan, NFSIllustrated Tom Cargill, C++ Programming Style William R. Cheswick/Steven M. Bellovin/Aviel D. Rubin, Firewalls and Internet Security, Second Edition: Repelling the Wily Hacker David A. Curry, UNIX®System Security: AGuide for Users and System Administrators Stephen C. Dewhurst, C++ Gotchas: Avoiding Common Problems in Coding and Design Dan Farmer/Wietse Venema, Forensic Discovery Erich Gamma/Richard Helm/Ralph Johnson/John Vlissides, Design Patterns: Elements of Reusable Object- Oriented Software Erich Gamma/Richard Helm/Ralph Johnson/John Vlissides, Design Patterns CD: Elements of Reusable Object- Oriented Software Peter Haggar, Practical Java™Programming Language Guide David R. Hanson, C Interfaces and Implementations: Techniques for Creating Reusable Software Mark Harrison/Michael McLennan, Effective Tcl/Tk Programming: Writing Better Programs with Tcl and Tk Michi Henning/Steve Vinoski, Advanced CORBA®Programming with C++ Brian W. Kernighan/Rob Pike, The Practice of Programming S. Keshav, An Engineering Approach to Computer Networking: ATM Networks, the Internet, and the Telephone Network 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, 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 Robert B. Murray, C++ Strategies and Tactics David R. Musser/Gillmer J. Derge/Atul Saini, STLTutorial and Reference Guide, Second Edition: C++ Programming with the Standard Template Library John K. Ousterhout, Tcl and the Tk Toolkit Craig Partridge, Gigabit Networking Radia Perlman,Interconnections, Second Edition: Bridges, Routers, Switches, and Internetworking Protocols Stephen A. Rago, UNIX®System V Network Programming Eric S. Raymond, The Art of UNIX Programming Marc J. Rochkind, Advanced UNIX Programming, Second Edition Curt Schimmel, UNIX®Systems for Modern Architectures: Symmetric Multiprocessing and Caching for Kernel Programmers W. Richard Stevens, TCP/IP Illustrated, Volume 1: The Protocols W. Richard Stevens, TCP/IP Illustrated, Volume 3: TCP for Transactions, HTTP, NNTP, and the UNIX® Domain Protocols W. Richard Stevens/Bill Fenner/Andrew M. Rudoff, UNIX Network Programming Volume 1, Third Edition: The Sockets Networking API W. Richard Stevens/Stephen A. Rago, Advanced Programming in the UNIX®Environment, Second Edition W. Richard Stevens/Gary R. Wright, TCP/IP Illustrated Volumes 1-3 Boxed Set John Viega/Gary McGraw, Building Secure Software: How to Avoid Security Problems the Right Way Gary R. Wright/W. Richard Stevens, TCP/IP Illustrated, Volume 2: The Implementation Ruixi Yuan/W. Timothy Strayer, Virtual Private Networks: Technologies and Solutions Visit www.awprofessional.com/series/professionalcomputing for more information about these titles. More Effective C++ 35 New Ways to Improve Your Programs and Designs Scott Meyers Upper Saddle River, NJ • Boston • Indianapolis • San Francisco New York • Toronto • Montreal • London • Munich • Paris • Madrid Cape Town • Sydney • Tokyo • Singapore • Mexico City 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 authors 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 [email protected] For sales outside the United States please contact: International Sales [email protected] Library of Congress Cataloging-in-Publication Data Meyers, Scott (Scott Douglas) More effective C++: 35 new ways to improve your programs and designs / Scott Meyers. p. cm. — (Addison-Wesley professional computing series) Includes bibliographical references and index. ISBN 0-201-63371-X (paperback: alk. paper) 1. C++ (Computer program language) I. Series. QA76.73.C153M495 1996 005.13'3—dc20 95–47354 CIP Copyright © 1996 by Addison-Wesley 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 per- missions, write to: Pearson Education, Inc Rights and Contracts Department 501 Boylston Street, Suite 900 Boston, MA 02116 Fax (617) 671-3447 ISBN-13: 978-0-201-63371-9 ISBN-10: 0-201-63371-X Text printed in the United States on recycled paper at Courier in Stoughton, Massachusetts. Twenty-fourth printing April 2007 For Clancy, my favorite enemy within. This page intentionally left blank Contents Acknowledgments xi Introduction 1 Basics 9 Item 1: Distinguish between pointers and references. 9 Item 2: Prefer C++-style casts. 12 Item 3: Never treat arrays polymorphically. 16 Item 4: Avoid gratuitous default constructors. 19 Operators 24 Item 5: Be wary of user-defined conversion functions. 24 Item 6: Distinguish between prefix and postfix forms of increment and decrement operators. 31 Item 7: Never overload &&, ||, or ,. 35 Item 8: Understand the different meanings of new and delete. 38 Exceptions 44 Item 9: Use destructors to prevent resource leaks. 45 Item 10: Prevent resource leaks in constructors. 50 Item 11: Prevent exceptions from leaving destructors. 58 Item 12: Understand how throwing an exception differs from passing a parameter or calling a virtual function. 61 Item 13: Catch exceptions by reference. 68 Item 14: Use exception specifications judiciously. 72 Item 15: Understand the costs of exception handling. 78

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.