Hacker News new | ask | show | jobs
by doldge 3211 days ago
So I'd like to learn more about modern C++ and how to write it, but I'm not really sure where to begin. I've tried a couple of times, but coming from a C background, my code tends towards C styling with only the occasional use of C++ features.

Is anyone aware of a good tutorial or reference list for writing good modern C++ (C++11 or newer, I guess)?

5 comments

The following is a readable and modern FAQ which describes most language features: https://isocpp.org/faq

My preferred reference for the language and standard library: http://en.cppreference.com/w/

The following is a longer guide on modern C++ style: https://github.com/isocpp/CppCoreGuidelines/blob/master/CppC...

As a newcomer to C++ myself, I found Stanley Lippman's C++ primer to be helpful. The latest edition includes the newer features.

And in case it helps, the main things I find myself using differently to C are:

- Smart pointers. If you're not using them, use them. They're amazing. Seriously. Never have to worry about freeing something ever again.

- Object oriented design.

- Const reference arguments.

- The occasional auto.

I'd second C++ Primer. It's a great overview of the language and has been updated for C++11. Unfortunately it was written too early for C++14 and beyond so if there is a newer edition planned (I've no idea) it might be worth the waiting. In any case C++11 was the big change for C++ so the fifth edition is still worth while.

One word of warning though, there's a confusing similarly titled book called "C++ Primer Plus" which you should avoid at all costs.

I'd add RAII to this list. Also, I find simple template functions to work as an incredibly powerful macro system.
I really enjoyed "Efficient Modern C++". I'd describe it as a good overview of new features in C++11 and 14, how to use them, and how they fit together, but I'm not sure whether it makes for a good "C++ for C programmers" book.
Check out this recent post by Simon Brand on this subject - https://blog.tartanllama.xyz/learning-cpp/
I really enjoyed "A Tour of C++" by Bjarne Stroustrup, which is a short book giving an overview of C++ features. It sticks to modern C++ practices from the very beginning.

Unfortunately, the book is C++11 only and correspondingly does not talk about C++14 or C++17.