I’m happy to announce that my new book on Data Member Initialization is published!
Have a look at the background story and how to get it.
About the book
As for my other books, I used the Leanpub platform for the PDF/Epub generation. Here’s the book’s website:
Why I wrote the book?
Initialization in C++ is a hot topic. With each C++ Standard, we’ll get some updates to the syntax, rules, and new capabilities. With this book, I wanted to clarify the confusion and make it simpler to reason about Modern C++ code.
Have I succeeded?
It’s C++, and you’ll see many opinions, special cases, and even contradicting examples. Yet, I’m happy with my content, and it should certainly improve your knowledge and expand your views.
The goal is to equip you with the following knowledge:
- The basic rules of data members and constructors.
- Essential information about copy constructors, move constructors, and destructors.
- How to efficiently initialize non-static data members using C++11 features like non-static data member initialization, inheriting, and delegating constructors.
- How to streamline working with static data members with inline variables from C++17.
- How to work with container-like members, non-copyable data members like
constdata members, or move-able only data members.
- Designated initializers from C++20.
The structure of the book
The book contains 15 chapters in the following structure:
- Chapters 1 to 5 create a foundation for the rest of the book. They cover constructors, destructors, and the basics of data members.
- Chapter 6 shows a use case for passing strings into constructors.
- Chapter 7 is a short quiz on constructors. You can check your knowledge from the first “part” of the book.
- Chapter 8 describe Non-static Data Member Initialization (NSDMI), a powerful feature from C++11 that improves how we work with data members.
- Chapter 9 serves as a practical summary for NSDMI, where you can solve a few exercises.
- Chapter 10 discusses how to initialize container-like data members.
- Chapter 11 contains information about non-regular data members and how to handle them in a class. You’ll learn about
unique_ptras a data member, and references.
- Chapter 12 shows how
inlinevariables from C++17 work.
- Chapter 13 moves to C++20 and describes Designated Initializers, a handy feature based on similar thing from the C language.
- Chapter 14 it’s the summary chapter with a demo that gathers most of the features described in the book.
- Chapter 15 is the final quiz with seven questions ranging from constructors to designated initializers.
Background for the book
Long story short: a few years ago, I wrote an article about NSDMI and got curious about how things work for data members. Last year I created a mini-course on the Educative platform. Starting this year, I wanted to bring the PDF version… and it looks like I discovered and described even more stuff :)
Here’s the initial article from 2015: Non Static Data Members Initialization - C++ Stories. And the course at Educative: Initializing Data Members: From C++11 till C++20.
Initially, after converting the lessons into a pdf, I got something around 60 pages. But then I realized it would be better to describe things with more examples and use cases. After digging, investigating, talking to various people… I ended up with 100 pages and now with 169 pages :) While the page count is not the only factor for the book, I believe it corresponds to the quality and practical knowledge I put inside.
As a new experiment, I put quizzes and exercises so that you can practice and check your knowledge. There’s no need to set up any coding environment for those tasks, as you can just use Compiler Explorer links and run all the code in the browser. This also works for 50+ examples you can find across the book - open the link and see how the code works.
Updates and plans
The book is 95% ready, and a few sections are still missing. I hope to complete them in July and August. If everything goes fine, then I’ll try to prepare the paper-back version in Fall.
Currently, the price is set to the minimum price available at Leanpub, but when the book is ready, it will go up to 9.99$.
This book wouldn’t be possible without valuable input from many C++ experts and friends.
I especially would like to thank to the following people:
- JFT (John Taylor),
- Mariusz Jaskółka,
- Florin Chertes (see LinkedIn),
- Konrad Jaśkowiec,
- Professor Boguslaw Cyganek (see his profile at AGH university page),
- Dawid Pilarski (see his blog @panicsoftware.com)
- Javier Estrada (see his blog at javierestrada.blog),
- Jonathan Boccara (from fluentcpp.com/),
- Andreas Fertig (see his blog @andreasfertig).
They spent a lot of time finding even little things that could be improved and extended.
With all of the help from those kind people, the book quality got better and better!
And please join the reviewer list by providing me with your suggestions and improvements. I’m happy to update the book.
How to Get the Book??
Here’s the link to the book @Leanpub:
Leanpub offers a 60-day refund period!
And several options to get it cheaper:
Buy together with my C++ Lambda Story ebook: Buy C++Lambda Story and Data Members in C++, 14.99$ instead of 29.98$
Support me on Patreon Become a Patron - starting from the 6$ tier, you’ll get the C++ Lambda Story ebook and the new book on Data Members. Plus a discount for C++17 in Detail. See all benefits here: Premium Content! - C++ Stories
You can also download a free sample that contains almost 60 pages (available from the Leanpub page)!