当前位置:网站首页>In insect classes and objects
In insect classes and objects
2022-06-26 13:48:00 【Hua Weiyun】
Scope of class
== Class defines a new scope ==, All members of a class are in the scope of the class . Define members outside the class , Need to use ==:: Scope resolver == Indicate which class domain the member belongs to
Class instantiation
The process of creating objects with class types , Called class instantiation
- == Class is just a model == The same thing , Defines which members of the class , Define a class == No actual memory space allocated == To store it
- A class can instantiate multiple objects ,== Instantiated object Take up actual physical space , Store class member variables ==
- Let's make an analogy .== Class to instantiate an object is like building a house out of a building plan , Class is like a blueprint ==, Just design what you need , But there are no physical buildings , The same class is just a design , Only the instantiated object can actually store data , Take up physical space
How class objects are stored
Object contains the members of the class
defects : The member variables in each object are different , But call the same function , If stored in this way , When a class creates multiple objects ,== A copy of the code is saved in each object , Save the same code multiple times , Waste space . So what's the solution ?==
Save only member variables , Member functions are stored in public code snippets
== The size of a class , In fact, it is in this class ” Member variables ” The sum of the , Of course, memory alignment is also necessary , Notice the size of the empty class , Empty classes are special , The compiler gives an empty class a byte to uniquely identify the class .==
Structure memory alignment rules
- The first member is offset from the structure by 0 The address of .
- Other member variables are aligned to a number ( Align numbers ) An integral multiple of the address of . == Be careful : Align numbers = Compiler default alignment number And The smaller value of the member size .==
VS The default alignment number in is 8- The total size of the structure is :== Maximum number of alignments ( The maximum of all variable types and the minimum of default alignment parameters ) Integer multiple .==
- If the structure is nested , The nested structure is aligned to an integral multiple of its maximum alignment , The overall size of the structure is
All maximum alignments ( The number of alignments with nested structures ) Integer multiple .
this The pointer
this Pointer leading out
At this point, someone should say that they are accessing the same function , So how to visit their respective dates
this The properties of the pointer
- this The type of pointer : Class types * const
- Only in “ Member functions ” Internal use of
- ==this Pointer is essentially a parameter of a member function ==, When an object calls a member function , Pass the object address as an argument to this Shape parameter . therefore == Objects are not stored this The pointer ==.
- ==this Pointer is the first implied pointer parameter of a member function , Generally, the compiler passes through ecx Register auto transfer , No need for user delivery ==
【 Interview questions 】
==this Where does the pointer exist ?==
this The pointer is stored in the stack , because this It's a parameter , Parameters , Local variables are in the stack . But different compilers have some differences , Even different versions of the same compiler will be a little different , such as vs13 It's using ecx Register stored ,vs19 It's using rcx Register stored
==this Can the pointer be null ?==
Look at a disgusting question before you say this
therefore this Cannot be null pointer , Null pointer compilation does not report errors , Because he is not a grammatical error , The compiler can't check
边栏推荐
- Thinking caused by the error < note: candidate expectations 1 argument, 0 provided >
- Echart stack histogram: add white spacing effect setting between color blocks
- Ubuntu installation and configuration PostgreSQL (18.04)
- 古瑞瓦特冲刺港交所上市:创下“多个第一”,获IDG资本9亿元投资
- Embedded virlog code running process
- Beifu PLC based on NT_ Shutdown to realize automatic shutdown and restart of controller
- 同花顺股票开户选哪个证券公司是比较好,比较安全的
- Mysql database explanation (IV)
- [how to connect the network] Chapter 2 (middle): sending a network packet
- Network remote access using raspberry pie
猜你喜欢
Mysql database explanation (III)
Input text to automatically generate images. It's fun!
爱可可AI前沿推介(6.26)
[how to connect the network] Chapter 2 (Part 1): establish a connection, transmit data, and disconnect
What features are added to Photoshop 2022 23.4.1? Do you know anything
[how to connect the network] Chapter 1: the browser generates messages
Use of wangeditor rich text editor
Logical operation
Pytorch based generation countermeasure Network Practice (7) -- using pytorch to build SGAN (semi supervised GaN) to generate handwritten digits and classify them
Learn how to develop owl components by hand (7): practical use of owl projects
随机推荐
去某东面试遇到并发编程问题:如何安全地中断一个正在运行的线程
Es sauvegarde et restauration des données par instantané
Nlp-d60-nlp competition D29
KITTI Tracking dataset whose format is letf_ top_ right_ bottom to JDE normalied xc_ yc_ w_ h
Tips for using nexys A7 development board resources
Connection migration for DataGrid configuration
sed编辑器
8.Ribbon负载均衡服务调用
Es6: iterator
网络远程访问的方式使用树莓派
Bifu divides EtherCAT module into multiple synchronization units for operation -- use of sync units
Es snapshot based data backup and restore
Custom encapsulation drop-down component
李航老师新作《机器学习方法》上市了!附购买链接
免费的机器学习数据集网站(6300+数据集)
D中不用GC
Ring queue PHP
三维向量的夹角
Basic methods for network diagnosis and hardware troubleshooting of Beifu EtherCAT module
NVM installation tutorial