virtual functions

C++ programmer's guide to undefined behavior: part 10 of 11

Your attention is invited to the tenth part of an e-book on undefined behavior. This is not a textbook, as it's intended for those who are already familiar with C++ programming. It's a kind of C++ programmer's guide to undefined behavior and to its most secret and exotic corners. The book was written by Dmitry Sviridkin and edited by Andrey Karpov.

C++ programmer's guide to undefined behavior: part 10 of 11

by Dmitry Sviridkin

From the article:

As you can see from the backtrace, the problematic object whose destructor caused the crash was a vector of strings in libgtest.so. In GTest sources, I found that this vector is a global variable where InitGoogleTest() stored recognized command line arguments. It's just a global variable declared in the compiled file and not presented in the header file. All seemed fine, except for one detail: it wasn't marked as static and was not wrapped in an anonymous namespace. So what? It worked, didn't it? Yeah, it worked. The trick was how the gMock library is built. Let's reproduce it step by step.

Virtual function calls in constructors and destructors

In different programming languages, the behavior of virtual functions differs when it comes to constructors and destructors. Incorrect use of virtual functions is a classic mistake. Developers often use virtual functions incorrectly. In this article, we discuss this classic mistake.

Virtual function calls in constructors and destructors

by Andrey Karpov

From the article:

So, what's the problem? You can find this information in any C++ programming book. The problem is that it's easy to forget about it! Thus, some programmers assume that foo and bar functions are called from the most derived C class. People keep asking the same question on forums: "Why does the code run in an unexpected way?" I think now you understand why it's easy to make a mistake in such code. Especially if you write code in other languages where the behavior is different. Let's look at the code fragment in C#.