问题描述
我们有用于?
推荐答案
首先,vtables的使用是实现定义的,而不是标准强制的。
First of all, usage of vtables is implementation defined and not mandated by the standard.
对于使用vtable的实现,答案是:通常。你可能认为抽象类不需要vtable,因为派生类将有自己的vtable,但是在构造期间需要它:当基类被构造时,它将vtable指针设置为它自己的vtable。后来当输入派生类构造函数时,它将使用自己的vtable。
For implementations that use vtable, the answer is: Yes, usually. You might think that vtable isn't required for abstract classes because the derived class will have its own vtable, but it is needed during construction: While the base class is being constructed, it sets the vtable pointer to its own vtable. Later when the derived class constructor is entered, it will use its own vtable instead.
也就是说,在某些情况下,这不是必需的, 。例如,MS Visual C ++提供了 __ declspec(novtable)
标志来禁用纯接口类上的vtable生成。
That said, in some cases this isn't needed and the vtable can be optimized away. For example, MS Visual C++ provides the __declspec(novtable)
flag to disable vtable generation on pure interface classes.
这篇关于抽象类有VTABLE吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!