Part 3: All About Virtual Keyword in C++: How Does Virtual Destructor Works?

Finally, we are in the 3rd & last part of this series. We have already discussed how virtual function & virtual class/inheritance works internally in previous parts. We left one topic i.e. “How Does Virtual Destructor Works?” which we will see now. As usual, before learning anything new I usually start with “Why Do We Need It in the First Place?” Why Do We Need a Virtual Destructor? We will understand this with our earlier example(slightly twisted): 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 class protocol_t { private: uint8_t *_type; // storage ....

September 12, 2019 · 6 min · 1194 words · Vishal Chovatiya

Part 1: All About Virtual Keyword in C++: How Does Virtual Function Works Internally?

“All About Virtual Keyword in C++” is a series of articles(total of three, PART 1, PART 2, PART 3) describe working of the virtual keyword in different scenarios. This article mostly focuses on “How Does Virtual Function Works Internally?”. In other words, How dynamic dispatch done in C++! Although I am not a compiler writer, but this is what I have learned so far from various sources, courses, books & disassembly of C++ program....

September 11, 2019 · 9 min · 1746 words · Vishal Chovatiya

Part 2: All About Virtual Keyword in C++: How Does Virtual Base Class Works Internally?

In PART 1 of “All About Virtual Keyword in C++” series, we have discussed “How Does Virtual Function Works Internally?”. So, in this article, I will discuss “How Does Virtual Base Class Works Internally?”. I am iterating the same thing which I have mentioned in the earlier article as well that implementation of a virtual mechanism is purely compiler dependent. So, there is no C++ standard is defined for such dynamic dispatch....

September 11, 2019 · 6 min · 1249 words · Vishal Chovatiya