INTRODUCTION

FOR MANY YEARS, C++ has served as the de facto language for writing fast, powerful, and enterprise-class object-oriented programs. As popular as C++ has become, the language is surprisingly difficult to grasp in full. There are simple, but powerful, techniques that professional C++ programmers use that don’t show up in traditional texts, and there are useful parts of C++ that remain a mystery even to experienced C++ programmers.

Too often, programming books focus on the syntax of the language instead of its real-world use. The typical C++ text introduces a major part of the language in each chapter, explaining the syntax and providing an example. Professional C++ does not follow this pattern. Instead of giving you just the nuts and bolts of the language with little real-world context, this book will teach you how to use C++ in the real world. It will show you the little-known features that will make your life easier, and the reusable coding patterns that separate novice programmers from professional programmers.

WHO THIS BOOK IS FOR

Even if you have used the language for years, you might still be unfamiliar with the more-advanced features of C++ or might not be using the full capabilities of the language. Perhaps you write competent C++ code, but would like to learn more about design in C++ and good programming style. Or maybe you’re relatively new to C++, but want to learn the “right” way to program from the start. This book will meet those needs and bring your C++ skills to the professional level.

Because this book focuses on advancing from basic or intermediate knowledge of C++ to becoming a professional C++ programmer, it assumes that you have some knowledge of the language. Chapter 1 covers the basics of C++ as a refresher, but it is not a substitute for actual training and use of the language. If you are just starting with C++, but you have significant experience in C, you should be able to pick up most of what you need from Chapter 1.

In any case, you should have a solid foundation in programming fundamentals. You should know about loops, functions, and variables. You should know how to structure a program, and you should be familiar with fundamental techniques such as recursion. You should have some knowledge of common data structures such as hash tables and queues, and useful algorithms such as sorting and searching. You don’t need to know about object-oriented programming just yet — that is covered in Chapter 3.

You will also need to be familiar with the compiler you will be using to develop your code. This book does not provide directions for using individual compilers. Refer to the documentation that came with your compiler for a refresher.

WHAT THIS BOOK COVERS

Professional C++ is an approach to C++ programming that will both increase quality of your code and improve your programming efficiency. This second edition of Professional C++ includes discussions on the new C++11 features throughout the whole book. The new C++11 features are not just isolated to a few chapters or sections, instead, almost all examples have been updated to use those new features when appropriate.

cross.gif

C++11, the full ISO name of which is ISO/IEC 14882:2011(E), is the latest C++ standard. The C++11 standardization process started around the beginning of the millennium. During this process, the draft standard was known as C++0x.

Professional C++ teaches more than just the syntax and language features of C++. It also emphasizes programming methodologies, reusable design patterns, and good programming style. The Professional C++ methodology incorporates the entire software development process — from designing and writing code, to testing, debugging, and working in groups. This approach will enable you to master the C++ language and its idiosyncrasies, as well as take advantage of its powerful capabilities for large-scale software development.

Imagine someone who has learned all of the syntax of C++ without seeing a single example of its use. He knows just enough to be dangerous! Without examples, he might assume that all code should go in the main() function of the program, or that all variables should be global — practices that are generally not considered hallmarks of good programming.

Professional C++ programmers understand the correct way to use the language, in addition to the syntax. They recognize the importance of good design, the theories of object-oriented programming, and the best ways to use existing libraries. They have also developed an arsenal of useful code and reusable ideas.

By reading and understanding this book, you will become a professional C++ programmer. You will expand your knowledge of C++ to cover lesser-known and often misunderstood language features. You will gain an appreciation for object-oriented design, and acquire top-notch debugging skills. Perhaps most important, you will finish this book armed with a wealth of reusable ideas that can be applied to your actual daily work.

There are many good reasons to make the effort to be a professional C++ programmer, as opposed to a programmer who knows C++. Understanding the true workings of the language will improve the quality of your code. Learning about different programming methodologies and processes will help you to work better with your team. Discovering reusable libraries and common design patterns will improve your daily efficiency and help you stop reinventing the wheel. All of these lessons will make you a better programmer and a more valuable employee. While this book can’t guarantee you a promotion, it certainly won’t hurt.

HOW THIS BOOK IS STRUCTURED

This book is made up of five parts.

Part I, “Introduction to Professional C++,” begins with a crash course in C++ basics to ensure a foundation of C++ knowledge. Following the crash course, Part I explores C++ design methodologies. You will read about the importance of design, the object-oriented methodology, the importance of code reuse, and how to write readable C++ code.

Part II, “C++ Coding the Professional Way,” provides a technical tour of C++ from the Professional point of view. You will read about how to create reusable classes, and how to leverage important language features such as inheritance. You will also learn about the unusual and quirky parts of the language, techniques for input and output, professional-grade error handling, and how to work with strings and regular expressions. This part also explains the C++ Standard Library, including containers, iterators, algorithms, and how to customize and extend the library to your needs. You will also read about some additional libraries available in the standard such as the libraries to work with time and random numbers.

Part III, “Mastering Advanced Features of C++,” demonstrates how you can get the most out of C++. This part of the book exposes the mysteries of C++ and describes how to use some of its more-advanced features. You will read about the best ways to manage memory in C++, how to implement advanced operator overloading, how to write templates, and how to use multithreaded programming to take advantage of multiprocessor and multicore systems.

Part IV, “C++ Software Engineering,” focuses on writing enterprise-quality software. You’ll read about the engineering practices being used by programming organizations today; software testing concepts, such as unit testing and regression testing; techniques used to debug C++ programs; how to write efficient C++ code; solutions for cross-language and cross-platform code; and how to incorporate design techniques, frameworks, and conceptual object-oriented design patterns into your own code.

The book concludes with a useful chapter-by-chapter guide to succeeding in a C++ technical interview, an annotated bibliography, and a summary of the C++ header files available in the standard. You will also find a practical reference guide to the C++ Standard Library on the supplemental website for this book at www.wrox.com. This reference guide is called “the Standard Library Reference resource on the website” throughout this book.

WHAT YOU NEED TO USE THIS BOOK

All you need to use this book is a computer with a C++ compiler. This book focuses only on parts of C++ that have been standardized, and not on vendor specific compiler extensions.

image This book includes new features introduced in the C++11 standard. At the time of this writing, there were no compilers yet supporting all new C++11 features. GCC 4.6 running on Linux and Microsoft Visual C++ 2010 running on Windows were used for testing code samples. GCC 4.6 supports a lot of new features, but not yet all. Examples using the following C++11 features could not be tested with the version of GCC 4.6 that was available:

  • The final and override keywords
  • User defined literals
  • In-class non-static data member initialization
  • Template aliases
  • Delegating constructors
  • Inheriting constructors

The second compiler used for testing was Microsoft Visual C++ 2010, however, it supports less C++11 features than GCC 4.6. Notably missing from VC++ 2010 are range-based for loop, uniform initialization, variadic templates, and the threading library, among others.

pen.gif

The supplemental website for this book at www.wrox.com contains an extra appendix that lists all C++11 features and whether a compiler supports a feature or not.

CONVENTIONS

To help you get the most from the text and keep track of what’s happening, we’ve used a number of conventions throughout the book.

cross.gif

Boxes like this one hold important, not-to-be-forgotten information that is directly relevant to the surrounding text.

pen.gif

Tips, hints, tricks, and asides to the current discussion are placed in boxes like this one.

As for styles in the text:

We highlight important words when we introduce them.

We show keyboard strokes like this: Ctrl+A.

We show filenames and code within the text like so: monkey.cpp.

We show URLs like this: www.wrox.com.

We present code in two different ways:

In code examples we highlight new and important code like this.
 
Code that's less important in the present context or that has been shown before is formatted like this.

image Paragraphs, sections, or chapters that are specific to the new C++11 standard have a little C++11 icon on the left, just as this paragraph does.

SOURCE CODE

As you work through the examples in this book, you may choose either to type in all the code manually or to use the source code files that accompany the book. All of the source code used in this book is available for download at www.wrox.com. Once at the site, locate the book’s title (either by using the Search box or by using one of the title lists), and click the Download Code link on the book’s details page to obtain all the source code for the book.

pen.gif

Because many books have similar titles, you may find it easiest to search by ISBN; for this book the ISBN is 978-0-470-93244-5.

Alternatively, you can go to the main Wrox code download page at www.wrox.com/dynamic/books/download.aspx to see the code available for this book and all other Wrox books.

Once you’ve downloaded the code, just decompress it with your favorite decompression tool.

ERRATA

We make every effort to ensure that there are no errors in the text or in the code. However, no one is perfect, and mistakes do occur. If you find an error in one of our books, such as a spelling mistake or faulty piece of code, we would be very grateful for your feedback. By sending in errata you may save another reader hours of frustration, and at the same time you will be helping us provide even higher-quality information.

To find the errata page for this book, go to www.wrox.com and locate the title by using the Search box or one of the title lists. Then, on the book details page, click the Book Errata link. On this page you can view all errata that has been submitted for this book and posted by Wrox editors. A complete book list including links to each book’s errata is also available at www.wrox.com/misc-pages/booklist.shtml.

If you don’t spot “your” error on the Book Errata page, go to www.wrox.com/contact/techsupport.shtml and complete the form there to send us the error you have found. We’ll check the information and, if appropriate, post a message to the book’s errata page and fix the problem in subsequent editions of the book.

P2P.WROX.COM

For author and peer discussion, join the P2P forums at p2p.wrox.com. The forums are a web-based system for you to post messages relating to Wrox books and related technologies, and interact with other readers and technology users. The forums offer a subscription feature to e-mail you topics of interest of your choosing when new posts are made to the forums. Wrox authors, editors, other industry experts, and your fellow readers are present on these forums.

At p2p.wrox.com you will find a number of different forums that will help you not only as you read this book, but also as you develop your own applications. To join the forums, just follow these steps:

1. Go to p2p.wrox.com and click the Register link.

2. Read the terms of use and click Agree.

3. Complete the required information to join as well as any optional information you wish to provide and click Submit.

4. You will receive an e-mail with information describing how to verify your account and complete the joining process.

pen.gif

You can read messages in the forums without joining P2P, but in order to post your own messages, you must join.

Once you’ve joined, you can post new messages and respond to messages other users post. You can read messages at any time on the web. If you would like to have new messages from a particular forum e-mailed to you, click the Subscribe to this Forum icon by the forum name in the forum listing.

For more information about how to use the Wrox P2P, be sure to read the P2P FAQs for answers to questions about how the forum software works, as well as many common questions specific to P2P and Wrox books. To read the FAQs, click the FAQ link on any P2P page.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset