An initial note: if you want to learn C++, by all means learn C++2011, the newest version. It removes quite a lot of the pain that comes with the power of C++. Also, don't fear books about C++2014, most compilers support it already!
Programming
- knowing the syntax of the language,
- knowing which features to use and when,
- writing readable code
- the compiler may get it, but will the next human reader?
- designing programs that make sense on a higher level
For C++, there are two language books that matter:
- The C Programming Language (Brian W. Kernighan, Denis M. Ritchie, TCPL)
This book isn't about C++, but, everything relevant to C is also relevant to C++. For example, all examples in this book compile as valid C++. This is not generally true of C, since C++ is more strict than its predecessor. But most quality C programs compile fine as C++. TCPL is a small book, and is widely hailed as one of the best 'The X Programming Language' books ever written. There is wisdom on almost every page. - The C++ Programming Language (4th edition, Bjarne Stroustrup)
An astounding book. It too has wisdom on every page. It also has 1400 pages. A hilarious review by Verity Stob can be found on The Register. In TCPL we read "C is not a big language, and it is not well served by a big book.". Hence the 1400 pages for C++. Even though the book is far too huge to read from cover to cover (although I think I've now hit almost every page), everyone should have a copy. It does indeed explain all of C++, and it does so pretty well. The book also is strong on C++ idioms that will make your life easier.
I want to reiterate that TC++PL is not a book to learn C++ from. It is a book to keep nearby while you are doing so, however. An extract of TC++PL "
A Tour of C++" is also available separately.
C++ is not just the language, but also a library. While the entire library is covered in TC++PL, for full details I recommend:
- The Standard C++ Library (Nikolai Josuttis)
Like TC++PL, this is a vast book. But it has Everything on the C++ libraries (also known as the Standard Template Library, STL). Get the second edition, which covers C++2011.
If you've read these three books and links, you'll be able to express yourself well in C++, and make good use of its libraries. However, you've not learned which of the many features to use, nor when. C++ is a powerful language. It has been said that in C, if you make a mistake, you blow off your own foot. C++ is then supposed to take your whole leg, and this is true.
Also, C++ is powerful enough to enable you to continue programming in your old language in C++. " I can write FORTRAN in any language". This will however not help you code better programs!
Making good use of C++
Here are three books, all by Scott Meyers, that greatly simplify the life of an aspiring C++ programmer:
- Effective C++ - lists common pitfalls, wonderful features and problematic areas to avoid. Most recently updated in 2005.
- More Effective C++ - more of the same, but getting a bit dated. Still worth your while.
- Effective STL - last updated in 2001, and like Effective C++, but then with a stronger focus on the standard library.
If you want to get one of these, get Effective C++. If you want two, get Effective STL too.
It is important to note that Scott has mostly completed a new book fully covering C++2014 (which can be seen as a refined version of C++2011. Most current compilers already support C++2014).
Once this book comes out, get it immediately as the previews already look great.
UPDATE: Various people have recommended '
C++ Primer' by Stanley Lippman cs. I don't know the book, but it has been updated for C++2011 and has received lots of praise. Please let me know your thoughts!
Writing readable code
All books mentioned above discuss coding styles, things (not) to do, but it is all rather spread out. Wisdom on how to write readable code be found in:
- The Practice of Programming (Brian W. Kernighan, Rob Pike, TPoP) - not specifically a C++ book, but has a a lot to say on how to structure code, when to optimize, when not, how to debug, how to prevent the need for debugging etc. Every office should have a copy.
- Linux Kernel Coding Style (Linus Torvalds) - specifically not about C++, but still has a lot to tell us in chapters 4 ('Naming'), 6 ('Functions'), and 8 ('Commenting').
TPoP should probably be read from cover to cover by every programmer wanting to improve their code.
Designing larger scale code
I know of only one book that touches on this, and it has been instrumental in my thinking:
- Large Scale C++ Software Design (John Lakos). Although dated in places, containing advice of use for people building on underpowered machines with very slow storage, this book is where I learned how to decompose complex problems into components that make sense. Of particular note is the material on cyclic dependencies in code. These quickly crop up, and make your components nearly impossible to test, since each component quickly relies on every other component.
Good luck learning C++!