Two weeks from now, on the 25th of May, is a very important event in the geek culture: Towel Day, and I’d love to celebrate it with you on Fluent C++! EDIT: check out the most beautiful piece of code that print 42 here! Towel day? Towel day is a yearly tribute to the fiction […]
In order to allow a function to behave in several different way, and to allow its caller to choose amongst these behaviours, we have several tools at our disposal. Plenty, actually. There are various sorts of polymorphisms embedded in the language such as virtual functions and templates. And we’ve also seen that a caller can […]
Enums and tag dispatching are two ways to introduce several behaviours in the same interface in C++. With them, we can pass arguments that determine a facet of how we want a function to behave. Even if enums and tag dispatching have that in common, they achieve it in a quite different way. Realizing what […]
Constructors lack something that the rest of the functions and methods have in C++: a name. Indeed, look at the following code: class MyClass { public: MyClass(); void doThis(); void doThat(); }; void doSomethingElse(MyClass const& x); Every routine has a name that says what it does, except for the constructor, which only bears the name […]
Who likes pointers? Those ancient creatures are a barrier to entry to C++, and a burden for those who braved the barrier. In the March 2018 C++ committee meeting in Jacksonville, Florida, the committee had a pretty ambitious agenda to work on. And one of the topics discussed was the deprecation, and later removal, of […]
If you want a glimpse of what the future of C++ might look like, here is a brief overview of one of the most popular recent proposals: metaclasses. It’s also interesting to know about metaclasses even for the present, because this proposal puts in perspective structuring elements of the language as it is today. Transcript […]
Singleton is one of the 23 design patterns of book of the Gang of Four, but over time it has evolved into an anti-pattern that developers tend to avoid nowadays. Today we have a guest on Fluent C++, Mihai Sebea. Mihai is here today to share with us his experience about rooting out singletons, and […]
“Should I use a struct, or a class?” Such is the question we sometimes ask ourselves when creating a new type. What’s the difference between struct and class in C++? How to to choose one or the other? This is the question we tackle in this week’s video: Transcript of the video: What’s the difference between a […]
One of the comments left on the Reddit thread of How to make if statements more understandable by /u/loup-vaillant, showed a suggestion to represent an else-if logic a different way, by using the ternary operator (?:) in a certain way. I find that suggestion interesting and I’d like to share it with you today. And while you’re […]
Early return statements are a controversial topic across many programming languages. Some people find that they improve readability because they avoid carrying a result variable down the end of a function. And some other people find they constitute a danger because they introduce complexity: with them, a function suddenly has several exit doors. Today I […]