当前位置:网站首页>Week 10 - task 0- execution process instance resolution of constructors and destructors
Week 10 - task 0- execution process instance resolution of constructors and destructors
2022-06-29 05:46:00 【sxhelijian】
【 subject 】 Reading programs , First analyze the execution result of the program , Run the program on the computer for comparison , And then through the single step execution to track the operation of the program , To understand the base class 、 Constructors in derived classes 、 The purpose of the destructor execution process .
The procedure is as follows :
Operation results and explanation :
| Running results | Description of operation results |
| The default constructor of part was called 0 The default constructor of part was called 0 The default constructor of part was called 0 The default constructor of whole was called 0 | The second part of the procedure is 60 Row definition object w1 when , The result of executing the constructor . For the base class part、 In a derived class part Object members execute the default constructor ; Finally, execute the derived class whole The statement in the function body of the default constructor of . |
| The constructor of part was called 1 The constructor of part was called 3 The constructor of part was called 2 The constructor of whole was called 4 | The second part of the procedure is 61 Row definition object w2 when , The result of executing the constructor . The process of calling the constructor is also based on the base class 、 Then derive the object members in the class , Finally, execute the function body of the derived class constructor . All the constructors executed here are constructors with parameters . Notice that you are creating objects w2(1,2,3,4) when , The first 48 The arguments of the line function call are :Part(1),two(2),one(3),data(4). Perhaps surprisingly , The number given is 1 3 2 4, instead of 1 2 3 4. This tells us ,w2 Object members in one Constructor for one(3) Execute before , Object members two Constructor for two(2) After the execution . Object members are constructed in the order they are defined in the object The order of ( See the first 20 and 21 That's ok ), Instead of the writing order in the constructor . Why? ? Because in one whole In the object , The data members are stored sequentially , Allocate space ,one before ,two After . C++ It's artificial language . Most of the questions are well founded , It's good to think more , But beginners often don't think . therefore , Once there is something you can't figure out , There are images left in the brain , With the further study, I will understand . |
| The destructor of whole was called 4 The destructor of part was called 2 The destructor of part was called 3 The destructor of part was called 1 | sign out f() When a function is called , End local object w2 Life cycle of , Execute destructor . The destructors to be called are in the reverse order of the previous constructors : First constructed, then deconstructed , The first analysis of the latter structure . |
| The destructor of whole was called 0 The destructor of part was called 0 The destructor of part was called 0 The destructor of part was called 0 | sign out f() When a function is called , End local object w1 Life cycle of , Execute destructor . w1 Than w2 First define , The destructor is executed later . The result is automatically determined by the system , Programmers need to understand the rules of the game . |
边栏推荐
- Problems with MySQL database query
- Open a new ecological posture | use WordPress remote attachment to store to Cos
- 5- (4-benzoimide phenyl) - 10,15,20-triphenylporphyrin (battph2) and its Zn complex (battpzn) / tetra (4-aminophenyl) porphyrin (tapph2) Qiyue supply
- After nine years of testing, the salary for interviewing Huawei is 10000. Huawei employees: the company doesn't have such a low salary position
- STI, one controller
- ICLR is going to have a big discussion on the deep generation model. Max welling and the winner of the AAAI million dollar award are here. Bengio is one of the organizers
- Signal slot mechanism
- Manual (functional) test 1
- CodeIgniter active record not equal - CodeIgniter active record not equal
- Notebook access desktop shared disk
猜你喜欢

ES6 Modularization: export /import

2022 recommended property management industry research report industry development prospect market investment analysis (the attachment is the link to the online disk, and the report is continuously up

PCI Verilog IP

2-nitro-5,10,15,20-tetra (4-methylphenyl) porphyrin copper (no2tmpp) Cu) /2-nitro-5,10,15,20-tetra (4-methylphenyl) porphyrin (no2tmpp) H2) Qiyue porphyrin supply
![Meso tetra (4-N, N, n-trimethylaminophenyl) porphyrin (ttmapp) /meso tetra - [4- (BOC threonine) aminophenyl] porphyrin (TAPP thr BOC) supplied by Qiyue](/img/a9/0869c4f39a96cff63d1e310292c46d.jpg)
Meso tetra (4-N, N, n-trimethylaminophenyl) porphyrin (ttmapp) /meso tetra - [4- (BOC threonine) aminophenyl] porphyrin (TAPP thr BOC) supplied by Qiyue

Plugin

5,10,15,20-tetra (3,5-dimethoxyphenyl) porphyrin ((tdmpp) H2) /2-nitro-5,10,15,20-tetra (3,5-dimethoxyphenyl) porphyrin copper (no2tdmpp) Cu) supplied by Qiyue

Boost the digital economy and face the future office | the launch of the new version of spreadjsv15.0 is about to begin

5000+ 字解读 | 产品经理:如何做好元器件选型?

What has urbanization brought to our mental health and behavior?
随机推荐
VLAN experiment
See how I do it step by step (I)
What has urbanization brought to our mental health and behavior?
Why can't the article be posted?
[high concurrency] deeply analyze the callable interface
Parsing rshub document auto generation API
2022-02 Microsoft vulnerability notification
Mongodb basic knowledge summary
Signal slot mechanism
Use VS to create a static link library Lib and use
Ctrip launched the "3+2" office mode. Are you sour?
QT precautions and RCC download address
C语言用 printf 打印 《爱心》《火星撞地球》等,不断更新
Review of MySQL knowledge points
Cloud native annual technology inventory is released! Ride the wind and waves at the right time
Le langage C imprime "Love", "Mars hit Earth" et ainsi de suite en utilisant printf, qui est constamment mis à jour
2022 recommended tire industry research report industry development prospect market analysis white paper
Modularization and modular specification commonjs
How to insert pseudo code into word documents simply and quickly?
ES6 Modularization: export /import