"1"nonstatic Member Functions (non-static member function)
One of the design guidelines for C + + is that nonstatic member function must be at least as efficient as the general nonmember function. That is, if we want to choose between the following two functions:
float magnitude3d (const point3d* _this) {...}; float Const {...};
Then choose member function should not bring any additional burden. This is because the "member function entity" has been converted internally by the compilation to the peer "nonmember function entity".
Here is the conversion step:
1, rewrite the function of the signature to insert an additional parameter into the member function, to provide an access pipeline, is a class object can call the function. This additional parameter is called the This pointer;
2, each "nonstatic data member access operation" is replaced by this pointer to access;
3. Re-write the member function as an external functions. "Mangling" the function name, making it a unique vocabulary in the program.
Now this function has been converted, and each invocation operation must be converted as well. So:
Obj.magnitude ();
has become:
MAGNITUDE_7POINT3DFV (&obj);
and
Ptr->magnitude ();
has become:
MAGNITUDE_7POINT3DFV (PTR);
"2" StaticMember Functions (static member function)
If Point3d::normalize () is a static member function, the following two call operations:
Obj.normalize ();
Ptr->normalize ();
will be converted to a general nonmember function call, like this:
NORMALIZE_7POINT3DSFV (); // obj.normalize (); NORMALIZE_7POINT3DSFV (); // ptr->normalize ();
"3"virtual Member Functions (dummy member function)
If normalize () is a virtual member function, then the following call:
Ptr->normalize ();
will be converted internally into:
(*ptr->vptr[1]) (PTR);
which
(1) vptr represents a pointer generated by the compiler, pointing to Virtual table. It is placed in each class object that declares (or inherits from) one or more virtual functions. In fact its name will also be "mangled", because in a complex class derivation system, there may be more than one vptrs.
(2) 1 is the index value of the virtual table slot, associated to the normalize () function.
(3) A second PTR represents the this pointer.
Various invocation methods for C + + Member functions