Deep Explore C ++ Object Model Chapter 4 DATA Language

zhaozj2021-02-16  58

4.1 MEMBER's various call modes NonStatic Member functions: Speed ​​and the general NonMember function have the same efficiency. The compiler will modify the NonStatic Member Function. Add this parameters, change the use of MEMBER DATA within the function, change the name of the function - equivalent to the nonmember function. This has a function name handling problem, joining the class name! Virtual Member Funciton: Call the virtual function through an Object call At this time, you need to transfer once via VPTR, and if you pass Class :: function, you will not be wrapped in unnecessary resolution. The use of Classs Scope Operator is clearly invoked to the resolution method of Virtual Funciton and NonStatic Member Funciton. Static Member Funciton: The main feature of Static Member Function is that there is no THIS pointer, so he cannot directly access its Class's nonStatic Data Members; it is not possible to be declared as Virtual, const, volatile; he does not need to via a certain Class Object can be called. His call speed and NonMember Funciton are almost. If you take the address of the Static Member Function, the river will be the direct "Nonmember function pointer" instead of "pointing the Class Member Funciton". 4.2 Virtual Member Function Virtual Funciton under multiple inheritance: When using the base class pointer to call the Virtual function, there may be two cases. Because the base Class Pointer may point out place in the beginning of the Derived Class Object, there may be an offset. When the general rule, the Derived Class Virtual Funciton is called to the "second or subsequent Base Class", the "necessary THIS pointer adjustment" operation with the operation is changed, and must be completed during the execution period. So how do you deal with it? It may have been adjusted! Really annoying! Hey! Thunk technology north quoted in the compiler! How to solve it? The SUN compiler is to provide a so-called "split function" technology; two functions are generated with the same algorithm, where the second is before returning, add the necessary OFFSET to the pointer, or by the Base1 or Derived pointer call function, Do not adjust the return value; if you call it through the base2 pointer, it is another function. What about IBM? "Hug Thunk is hugged in the Virtual function that is really called. Function Removes the implementation (1) Adjust the THIS pointer, then (2) executing the function code written by the programmer; 2) Part "! The MS method replaces the Thunk policy in so-called 'Address Points', which is about to rewrite the functionality of others (that is, overriding function) is looking forward to the address of 'introducing Virtual Class'.

转载请注明原文地址:https://www.9cbs.com/read-24321.html

New Post(0)