In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the principle of C++ virtual function table and how to use the relevant knowledge, the content is detailed and easy to understand, simple and fast operation, has a certain reference value, I believe that after reading the principle of this C++ virtual function table is what and how to use the article will have a harvest, let's take a look.
1. Virtual function table
Anyone who knows about C++ should know that virtual functions (Virtual Function) are implemented through a table of virtual functions (Virtual Table). Referred to as V-Table for short. In this table, the main is the address table of the virtual function of a class, which solves the problem of inheritance and coverage, and ensures that it can truly reflect the actual function. In this way, in an instance of a class with a virtual function, the table is allocated to the memory of the instance, so when we use the pointer of the parent class to manipulate a subclass, the virtual function table becomes important. it is like a map, indicating the function that should actually be called.
Here we focus on this virtual function table. C++ 's compiler should ensure that the pointer to the virtual function table exists at the forefront of the object instance (this is to ensure the highest performance of getting the virtual function table-if there are multiple layers of inheritance or multiple inheritance). This means that we get the virtual function table from the address of the object instance, and then we can traverse the function pointer and call the corresponding function.
After hearing me talk so much, I can feel that you may be more confused now than before. It doesn't matter, the following is a practical example, I believe you can understand it at a glance.
Suppose we have a class like this:
Class Base {public: virtual void f () {cout
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.