【发布时间】:2013-11-04 12:31:12
【问题描述】:
我对用纯 C 语言实现虚函数很感兴趣。这里是example of the implementation。然后通过指向基类的虚函数表的指针来实现派生类。为什么派生类没有vtable指针,而是使用基类的vtable。也许是因为它们的偏移量相同?
void myClassDerived_ctor(struct myClassDerived *this)
{
myClassBase_ctor(&this->base);
this->base.vtable = (void*)&myClassDerived_vtable + sizeof(void*); // used vtable of the base class
}
【问题讨论】:
标签: c++ c virtual-functions vtable