Effective C++: 50 Specific Ways To Improve Your Programs And Design

E-Book Overview

The first edition of Effective C++ sold nearly 100,000 copies and was translated into four languages. It's easy to understand why. Scott Meyers' practical approach to C++ described the rules of thumb employed by the experts-the things they almost always do or almost always avoid doing-to produce clear, correct, efficient code. Each of this book's 50 guidelines summarizes a way to write better C++, and the accompanying discussions are backed by specific examples. For this new edition, Meyers reworked every guideline in the book. The result is exceptional adherence to C++'s Draft International Standard, current compiler technology, and the latest insights into the use of C++ for real-world applications

E-Book Content

Effective C++ Second Edition 50 Specific Ways to Improve Your Programs and Designs Scott Meyers ~ TT ADDISON-WESLEY An imprint of Addison Wesley Longman, Inc. Reading, Massachusetts Harlow, England Menlo Park, California Berkeley, California Don Mills, Ontario Sydney Bonn Amsterdam Tokyo 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 Addison-Wesley was aware of a trademark claim, the designations have been printed in initial caps or all caps. The author and publisher have taken care in the preparation of this book, but make no express 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 discounts on this book when ordered in quantity for special sales. For more information, please contact: Corporate & Professional Publishing Group Addison Wesley Longman, Inc. One Jacob Way Reading, Massachusetts 01867 Library of Congress Cataloging-in-Publication Data Meyers, Scott (Scott Douglas) Effective C++ : 50 specific ways to improve your programs and designs / Scott Meyers. -- 2nd ed. p. em. Includes index. ISBN 0-201-92488-9 1. C++ (Computer program language) I. Title. QA76.73.C153M48 1997 005.13'3--dc21 97-24041 CIP Copyright © 1998 by Addison Wesley Longman, Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form, or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior consent of the publisher. Printed in the United States of America. Published simultaneously in Canada. 5 6 7 8 9 10 MA 01 00 99 98 5th Printing November, 1998 For Nancy, without whom nothing would be much worth doing. Wisdom and beauty form a very rare combination. - Petroniu8 Arbiter Satyricon, XCIV Contents Preface xiii AcknowledgDlents xvii Introduction 1 Shifting front C to c++ Item Item Item Item 1: 2: 3: 4: Prefer Prefer Prefer Prefer eonst and inline to #define. to . new and delete to malloe and free. C++-style comments. Mem.ory Managentent Use the same form in corresponding uses of new and delete. 6: Use delete on pointer members in destructors. 7: Be prepared for out-of-memory conditions. 8: Adhere to convention when writing operator new and operator delete. 9: Avoid hiding the "normal" form of new. 10: Write operator delete if you write opera tor new. 13 13 17 19 21 22 Item 5: Item Item Item Item Item Constructors, Destructors, and Assignment Operators Item 11: Declare a copy constructor and an assignment operator for classes with dynamically allocated memory. 23 24 25 33 37 39 49 49 x Contents Item 12: Prefer initialization to
You might also like

Laboratory In Software Engineering (eecs 6170)
Authors: Daniel Jackson , Rob Miller    168    0


Network Analysis: Methodological Foundations
Authors: Ulrik Brandes , Thomas Erlebach (auth.) , Ulrik Brandes , Thomas Erlebach (eds.)    183    0



Distributed Computing: Principles, Algorithms, And Systems
Authors: Ajay D. Kshemkalyani , Mukesh Singhal    112    0


Invitation To Fixed-parameter Algorithms
Authors: Rolf Niedermeier    122    0


Lectures On Image Processing
Authors: Morse B.S.    153    0




Object-oriented Programming Via Fortran 90-95
Authors: Ed Akin    154    0


Introduction To Programming With Fortran 77, 90, 95, 2003
Authors: Chivers , Sleightholme.    181    0