当前位置:网站首页>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
边栏推荐
- 团队管理的最关键因素
- Select tag - uses the default text as a placeholder prompt but is not considered a valid value
- MySQL configuration improves data insertion efficiency
- Embedded virlog code running process
- MongoDB系列之Window环境部署配置
- Global variable vs local variable
- ES基於Snapshot(快照)的數據備份和還原
- Es6: iterator
- Analysis of state transition diagram of Beifu NC axis
- Traverse the specified directory to obtain the file name with the specified suffix (such as txt and INI) under the current directory
猜你喜欢

Es snapshot based data backup and restore

免费的机器学习数据集网站(6300+数据集)

CloudCompare——泊松重建

VTK 圆柱体的生成与渲染

awk工具

I met the problem of concurrent programming in an interview: how to safely interrupt a running thread

12 SQL optimization schemes summarized by old drivers (very practical)

What features are added to Photoshop 2022 23.4.1? Do you know anything

Select tag - uses the default text as a placeholder prompt but is not considered a valid value

Guruiwat rushed to the Hong Kong stock exchange for listing: set "multiple firsts" and obtained an investment of 900million yuan from IDG capital
随机推荐
Awk tools
There are many contents in the widget, so it is a good scheme to support scrolling
Logical operation
LeetCode_ Stack_ Medium_ 150. evaluation of inverse Polish expression
Basic type of typescript
7.Consul服务注册与发现
虫子 STL string 下 练习题
Here Document免交互及Expect自动化交互
7.consul service registration and discovery
NVM installation tutorial
mysql配置提高数据插入效率
Luogu p3426 [poi2005]sza-template solution
5+api, clear application cache
character constants
Wechat applet SetData dynamic variable value sorting
7-16 monetary system I
Stack, LIFO
GO语言-管道channel
[how to connect the network] Chapter 2 (Part 1): establish a connection, transmit data, and disconnect
Traverse the specified directory to obtain the file name with the specified suffix (such as txt and INI) under the current directory









