Forgot your password?
typodupeerror
Book Reviews

+ - Book Review: C++ Primer (Fifth Edition)->

Submitted by
asgard4
asgard4 writes "Title: C++ Primer (Fifth Edition)
Authors: Stanley B. Lippman, JoséeLajoie, Barbara E. Moo
Publisher: Addison-Wesley
976 pages
ISBN-13: 978-0-321-71411-4
ISBN-10: 0-321-71411-3
Price: $59.99

The updated C++ language ISO standard released in September 2011 (called C++11 by most people instead of its full, glorious name ISO/IEC 14882:2011) extends C++ in a myriad of ways, both at a language and at a library level. Even though there aren’t any compilers that fully support all the new language extensions yet, C++ books are already getting updated to include the new features. Quite possibly one of the best books to learn C++ is the classic book C++ Primer by Lippman, Lajoie, and Moo, which received a significant facelift in its fifth edition to include most (but not all) new C++11 features.

Unlike other books that start with discussing the C subset of C++ and the more low-level, procedural features of the language, C++ Primer immediately introduces various higher-level features, such as classes and the use of the standard library types string and vector. I think this is a good choice, considering that the book is written for a target audience that is already familiar with programming, but just not in C++. The book is also a very good introduction to the new C++11 features for programmers that already have experience with the “old” C++98. To aid this subset of readers, the authors have kindly added little icons next to the text that discusses C++11.

After presenting a quick and simple example program, the book introduces how to define variables of different types and how to create compound data structures, followed by a brief look at the standard library string and vector classes. Almost all later examples in the book will use at least these basic types. This is followed by the usual tour through most of the different types of expressions and statements C++ offers.The book continues with a detailed discussion of functions, how they can be overloaded, how default arguments work, how the new C++11 constexpr functions work, and how argument types are converted when functions are called. The authors do a great job at covering almost all possible argument types, from passing C-style arrays as references, to functions that accept the new C++11 initializer lists or old-style ellipsis parameters. In general, I think this thoroughness is a good thing. At the same time, it shows the complexity of the language when it takes almost 60 pages to describe how functions are defined and called.The book concludes its first part with a basic look at classes and some hints to object-oriented programming in C++.

Part II of the book is a brief tour of parts of the C++ standard library, in particular IO streams, various sequential and associative containers (including the new C++ unordered containers) and finally dynamic memory and smart pointers. This part is almost an interlude before the book continues with more concepts with regards to classes in part III, in which the presented examples make use of the standard library facilities from part II. A whole chapter in part III is dedicated to copy control, quite an important and often not very well understood concept in C++. There is also ample discussion of the Rule of Three, which states that a class that requires a destructor also needs a copy constructor and an assignment operator. Of course, with the new C++11 rvalue references this becomes the Rule of Five, which requires that such a class should also have a move constructor and a move assignment operator. The discussion of rvalue references and moving objects in C++11 is excellent, in my opinion. Well worth the read, even for experienced C++98 developers.

The book continues with operator overloading and an in-depth look at polymorphism via virtual functions. The new C++11 keywords final and override are discussed, as well as virtual destructors and pure virtual functions. The final chapter in this part of the book is about templates. The discussion is quite detailed, with a good coverage of class templates, function templates, template specialization and the new variadic templates that were introduced with C++11. There is also ample treatment of how rvalue reference template parameters behave in template argument deduction — quite an interesting topic that has some surprising properties. When passing an lvalue reference to an rvalue reference template parameter, the deduced type is an lvalue reference because of how references get collapsed during argument deduction. C++ guru Scott Meyers recently called this type of rvalue reference a “universal reference” in talk he gave. (http://channel9.msdn.com/Shows/Going+Deep/Cpp-and-Beyond-2012-Scott-Meyers-Universal-References-in-Cpp11)

The final part of the book deals with a few more topics that didn’t fit anywhere else in the book.In particular, there is discussion of some more standard library classes (tuples, regular expressions, and random number generators), exception handling, namespaces, overloading the new and delete operators, and some other random topics. Overall, the book’s coverage of the language is pretty thorough, but there are some things that it doesn’t discuss or even bring up at all. For one thing, there is no mention of template metaprogramming. There is a short mention of the new C++11 type traits templates, which can be considered template metaprogramming to some degree, but that’s pretty much it. I think for a primer that’s alright.However, a short chapter that shows some basic metaprogramming with types might have been nice. Also, there is no mention of the new C++11 memory model, multi-threading, or thread-local storage.

Most of the changes introduced with C++11 are certainly useful in a lot of contexts and allow us to write more concise and modern C++ programs. However, I can’t shake the feeling that C++ — already an incredibly complex language to learn and even more difficult to master — has become so cluttered with features that it’s becoming a herculean task to teach the language. C++ Primer reinforces that feeling. While an excellent book at giving the reader a thorough introduction to the language, the book’s more than 900 densely information-packed pages confirm that learning C++11 takes a lot of dedication. Nevertheless, the book is a great guide along the journey, if the reader is willing to immerse herself in the intricacies of the C++ programming language. I highly recommend C++ Primer to any programmer interested in starting to learn the ropes of C++."

Link to Original Source
This discussion was created for logged-in users only, but now has been archived. No new comments can be posted.

Book Review: C++ Primer (Fifth Edition)

Comments Filter:

To err is human -- to blame it on a computer is even more so.

Working...