Function member of C ++ object model (1)

zhaozj2021-02-17  83

Chapter III Function Member

1.1. Three call modes of member functions

1.1.1. Non-static member functions

The efficiency of non-static member functions is the same, that is,

FLOAT MAGNITUDE (Const Point3D * _THIS) {...};

with

FLOAT POINT3D :: Magnitude () Const {...};

The efficiency is the same.

The conversion step of the member function is as follows (the work made by the compiler):

l Rewriting function prototype

// Non-static member function

Point3d :: Magnitude (Point3D * const this);

// constant non-static member function

Point3D :: Magnitude (const point3d * const this);

l Conversion to non-static data members is completed by the THIS pointer

{THIS-> xxxx}

l Remove the member function as an external function, process the function name, so that it is unique in the program

1.1.2. Virtual member function

l calls through the pointer

Point3D * PTR;

......

Ptr-> normalize ();

It will be converted to (* PTR-> VPTR [1]) (PTR) internally;

l Call via object

Point3D Obj;

Obj.Normalize ();

Since the compiler can determine that the call is definitely Point3D :: Normalize (), such a call will be converted to:

Normalize_7point3DEV (& obj); // The encoded function name maintains uniqueness throughout the program.

1.1.3. Static member function

Point3D * PTR;

......

Point3D Obj;

Ptr-> normalize ();

Obj.Normalize ();

It will be converted to Normalize_7Point3DEV () inside.

The main feature of the static member function is that there is no THIS pointer, followed by the second

1. Unable to access non-statist members in CLASS

2. Can't be declared as const, volatile or vitrual

You can call it without Class Object

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

New Post(0)