Deleting a derived class object using a pointer to a base class that has a non-virtual destructor results in undefined behavior. To correct this situation, the base class should be defined with a virtual destructor. Source: https://www.securecoding.c…
13.6 Why does a destructor in base class need to be declared virtual? 这道题问我们为啥基类中的析构函数要定义为虚函数.首先来看下面这段代码: class Foo { public: void f(); }; class Bar: public Foo { public: void f(); }; Foo *p = new Bar(); p->f(); 调用p->f()会调用基类中的f(),这是因为f()不是虚函数.为了调用派…
Memory Layout for Multiple and Virtual Inheritance(By Edsko de Vries, January 2006)Warning. This article is rather technical and assumes a good knowledge of C++ and some assembly language.In this article we explain the object layout implemented by gc…