What is Vtable in C++ [duplicate]

陌路散爱 提交于 2019-11-26 19:53:12

问题


Possible Duplicate:
why do I need virtual table?

What is vtAble in C++?
Got to know vtable is a virtual table which has an array of pointers to virtual functions. Is there an article with practical implementation? (Any walk through will be appreciated)


回答1:


V-tables (or virtual tables) are how most C++ implementations do polymorphism. For each concrete implementation of a class, there is a table of function pointers to all the virtual methods. A pointer to this table (called the virtual table) exists as a data member in all the objects. When one calls a virtual method, we lookup the object's v-table and call the appropriate derived class method.




回答2:


vTable (virtual table) is an implementation detail of dynamic dispatch (virtual methods).

See C++-Lite-Faq for more details.




回答3:


For all it's worth, it is not a standard C++ terminology. It is just an implementation detail used by the implementation to implement virtual functions/dynamic binding



来源:https://stackoverflow.com/questions/3554909/what-is-vtable-in-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!