Virtual method tables

后端 未结 3 824
南方客
南方客 2020-12-01 09:42

When discussing sealed classes, the term \"virtual function table\" is mentioned quite frequently. What exactly is this? I read about a method table a while ago (I don\'t re

3条回答
  •  -上瘾入骨i
    2020-12-01 10:03

    The definition for Virtual Function Table (often call vtable) is the same in C# and C++. It is an lookup table use internally by the runtime to achieve the polymorphic behaviors of abstract/virtual/override method.

    In simple you can imagine a base class with a virtual methodA will have a vtable that contains methodA. When derived class override methodA, the vtable for methodA inherits from the parent class but will now points to the methodA in the derived class rather than parent class.

提交回复
热议问题