How does virtual method invocation work in C++?

前端 未结 4 1484
隐瞒了意图╮
隐瞒了意图╮ 2020-11-30 14:38

How does Virtual Method Invocation work in C++?

相关标签:
4条回答
  • 2020-11-30 14:43

    Every class with at least one virtual method has it's virtual table - table of pointers to functions that are that class's methods.

    It's extensively used in COM.

    0 讨论(0)
  • 2020-11-30 14:43

    With VTables and function pointers. Virtual functions' function pointer will be listed in VTable
    MFC is using Message Map instead of Virtual function, which reduces the size limitation. If we use several virtual function VTable will end up with big size.

    0 讨论(0)
  • 2020-11-30 15:02

    Through virtual tables.

    Read this article, http://en.wikipedia.org/wiki/Virtual_table.

    I could explain it here, but the wikipedia does a better job than I could.

    0 讨论(0)
  • 2020-11-30 15:08

    The C++ standard doesn't specify how the virtual function mechanism should be implemented.

    That said, I think all current C++ compilers use virtual tables.
    The common way to do this for classes which contain at least one virtual function to have a hidden pointer to a so-called virtual table, where the addresses of the virtual functions for a specific class are entered in compiler-specific order.
    Each constructor will then set this hidden pointer to the virtual table of the class it belongs to.

    0 讨论(0)
提交回复
热议问题