C++11 for Programmers
Second Edition
Deitel Developer Series
Paul Deitel
Deitel & Associates, Inc.
Harvey Deitel
Deitel & Associates, Inc.
Upper Saddle River, NJ Boston Indianapolis San Francisco
New York Toronto Montreal London Munich Paris Madrid
Capetown 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
For sales outside the U. S., please contact:
International Sales
Visit us on the Web: informit.com/ph
Library of Congress Cataloging-in-Publication Data
On file
2014 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. To obtain permission to use material from this work, please submit a written request to Pearson Education, Inc., Permissions Department, One Lake Street, Upper Saddle River, New Jersey 07458, or you may fax your request to (201) 236-3290.
ISBN-13: 978-0-13-343985-4
ISBN-10: 0-13-343985-2
Text printed in the United States at RR Donnelley in Crawfordsville, Indiana..
First printing, February 2013
Trademarks
DEITEL, the double-thumbs-up bug and DIVE INTO are registered trademarks of Deitel and Associates, Inc.
Microsoft, Visual Studio and the Windows logo are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries.
Throughout this book, trademarks are used. Rather than put a trademark symbol in every occurrence of a trademarked name, we state that we are using the names in an editorial fashion only and to the benefit of the trademark owner, with no intention of infringement of the trademark.
To our review team:
Dean Michael Berris
Danny Kalev
Linda M. Krause
James P. McNellis
Robert C. Seacord
Jos Antonio Gonzlez Seco
We are grateful for your guidance and expertise.
Paul and Harvey Deitel
Contents
Chapter 24 and Appendices FK are PDF documents posted online at www.informit.com/title/9780133439854
Online Chapters and Appendices
Chapter 24 and Appendices FK are PDF documents posted online at www.informit.com/title/9780133439854
24 C++11 Additional Features
F C Legacy Code Topics
G UML 2: Additional Diagram Types
H Using the Visual Studio Debugger
I Using the GNU C++ Debugger
J Using the Xcode Debugger
K Test Driving a C++ Program on Mac OS X
[Note: The test drives for Windows and Linux are in .]
Preface
The chief merit of language is clearness ...
Galen
Welcome to C++11 for Programmers! This book presents leading-edge computing technologies for software developers.
We focus on software engineering best practices. At the heart of the book is the Deitel signature live-code approachconcepts are presented in the context of complete working programs, rather than in code snippets. Each complete code example is accompanied by live sample executions. All the source code is available at
www.deitel.com/books/cpp11fp
As you read the book, if you have questions, were easy to reach at
Well respond promptly. For book updates, visit www.deitel.com/books/cpp11fp
. Join our social media communities on Facebook (www.deitel.com/DeitelFan
), Twitter (@deitel
), Google+ (gplus.to/deitel
) and LinkedIn (bit.ly/DeitelLinkedIn
), and subscribe to the Deitel Buzz Online newsletter (www.deitel.com/newsletter/subscribe.html
).
Features
Here are the key features of C++11 for Programmers.
C++11 Standard
The new C++11 standard, published in 2011, motivated us to write C++11 for Programmers. Throughout the book, each new C++11 feature we discuss is marked with the 11 icon you see here in the margin. These are some of the key C++11 features of this new edition:
Conforms to the new C++11 standard. Extensive coverage of many of the key new C++11 features ().
Code thoroughly tested on three popular industrial-strength C++11 compilers. We tested the code examples on GNU C++ 4.7, Microsoft Visual C++ 2012 and Apple LLVM in Xcode 4.5.
Smart pointers. Smart pointers help you avoid dynamic memory management errors by providing additional functionality beyond that of built-in pointers. We discuss unique_ptr
in , and shared_ptr
and weak_ptr
in Chapter 24.
Fig. 1. A sampling of C++11 features in C++11 for Programmers.
and enhanced it with new C++11 features. The vast majority of your data structure needs can be fulfilled by reusing these Standard Library capabilities.
Online Chapter 24, C++11: Additional Topics. In this chapter, we present additional C++11 topics. The new C++11 standard has been available since 2011, but not all C++ compilers have fully implemented the features. If all three of our key compilers already implemented a particular C++11 feature at the time we wrote this book, we generally integrated a discussion of that feature into the text with a live-code example. If any of these compilers had not implemented that feature, we included a bold italic heading followed by a brief discussion of the feature. Many of those discussions will be expanded in online Chapter 24 as the features are implemented. Placing the chapter online allows us to evolve it dynamically. This chapter includes discussions of regular expressions, the shared_ptr
and weak_ptr
smart pointers, move semantics and more. You can access this chapter at:
www.informit.com/title/9780133439854
Random Number generation, simulation and game playing.