Organize it, share it, and welcome to correct it. For_wind
1. nonstatic member functionsIt is at least as efficient as the general nonmember function. The "member function entity" has been converted to a peer "Nonmemer function entity" internally by the compiler. Conversion Step: Rewrite function prototype (signature) to place extra arguments this pointer is changed by the this pointer to access the NONSTATIC data member, name mangling handler function name as the only external function name, and the name return Optimization of value
2, virtual member functionsTwo ways to call:
1 invokes a virtual function via a class object, which the compiler treats as a generic nonstatic member function for resolved.
2 through a pointer or reference call, through the vptr, point to Virtual table, through the index value, association to the virtual function.
Execution polymorphism: A derived class object is addressed by a pointer (or reference) to a public base class.
Specific: Preparation: Placement vptr point to the table; Assign a table index value to each virtual function. Perform task: "Activates" the virtual function in a specific virtual table slot.
A class will only have a virtual table. Each table contains the addresses of all active virtual functions function entities in its corresponding class object. These active virtual functions include: (1)
The function entity defined by this class, rewrite (overriding) a possible base class virtual function entity. (2)
function entities that inherit base class。 (3)
pure_virtual_called () function entity。 (Represents the pure virtual function, or sometimes as an execution-time exception handler)
virtual functions under multiple inheritanceThe complexity lies in the second and subsequent base class, and "the This pointer must be adjusted during the execution period." Adjustment method: Thunk technology, Address points technology (Microsoft)
virtual functions under the fictitious inheritanceRecommendation: Do not declare the nonstatic data members in a virtual base class. Because it's too complicated.
3. Static member functionIts main features: there is no this pointer related secondary attribute: Nonstatic members that cannot be directly accessed in their class cannot be declared const, volatile or virtual does not need to be invoked through class object, although this is often used. Takes the address of a static member function, obtains its place in memory, and its address type is a pointer to a nonmember function: this pointer takes the "nonstatic class member" accessed in the member function Bound to the corresponding member in object.
references and recommended materials:Deep Exploration of C + + object models
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.