继承的析构函数是否包含在虚拟 table 中?

Are inherited destructors contained inside the virtual table?

如果我的编译器使用虚拟 tables,B 的虚拟 table 会是什么样子? A::~A 会在 B 的虚拟 table 中吗?

struct A{
    virtual ~A()
    {
        cout<<"A::destructor"<<endl;
    }
};
struct B:public A{
    ~B()
    {
        cout<<"B::destructor"<<endl;
    }
};

不,B 的虚拟 table 中不会有 ~A。它将在与析构函数对应的条目中具有 ~B 。毕竟,一旦析构函数被声明为虚函数,所有派生的析构函数都是虚函数。

因此 delete 表达式将始终调用正确的析构函数。 B 的基础子对象 A 被销毁的方式,可以简单地通过编译器 静态 注入对 ~A 的调用来完成~B 结束。概念上是这样的:

~B()
{
    cout<<"B::destructor"<<endl;

    //User defined code ended. Compiler generated one is here
    static_cast<A*>(this)->A::~A();
}

这一切都在深入研究 可能的 实施细节。 None 其中包含在 C++ 标准中。