Monday, May 22, 2017

C++ vTable and vPtr

What is a virtual table?

Virtual Table is a lookup table of function pointers used to dynamically bind the virtual functions to objects at run time. It is not intended to be used directly by the program, and as such there is no standardised way to access it.

Every class that uses virtual functions (or is derived from a class that uses virtual functions) is given it's own virtual table as a secret data member. This table is set up by the compiler at compile time. A virtual table contains one entry as a function pointer for each virtual function that can be called by objects of the class. It stores NULL pointer to pure virtual functions in ABC. Virtual Table is created even for classes that have virtual base classes. In this case, the vTable has pointer to the shared instance of the base class along with the pointers to the class's virtual functions if any.

What is a vptr?

This vtable pointer or _vptr, is a hidden pointer added by the compiler to the base class and this pointer is pointing to the virtual table of that particular class. This _vptr is inherited to all the derived classes. Each object of a class with virtual functions transparently stores this _vptr. Call to a virtual function by an object is resolved by following this hidden _vptr.

references
https://www.quora.com/What-are-vTable-and-VPTR-in-C++

1 comment:

  1. -- Living Mobile --: C++ Vtable And Vptr >>>>> Download Now

    >>>>> Download Full

    -- Living Mobile --: C++ Vtable And Vptr >>>>> Download LINK

    >>>>> Download Now

    -- Living Mobile --: C++ Vtable And Vptr >>>>> Download Full

    >>>>> Download LINK ZT

    ReplyDelete