当前位置:网站首页>Class part2
Class part2
2022-07-03 14:50:00 【III VII】
14.3
Implementing member functions in class definitions inline
The functions implemented in the definition of a class are inline functions ;
As shown below :
public:
void addhour(int tmphour)
{
Hour=Hour+tmphour;
}
At the end of a member function const
If you add const Then the member variable value cannot be modified ;
void noone()const
{
Hour+=10; // error , Changed member variables ;
}
mutable
use mutable Character to modify member variables, you can modify member variables
mutable int myHour;
void noone()const
{
myHour+=10; // No mistake. ;
}
this The pointer
this Understanding of pointer :
When calling a member function , The compiler is responsible for passing the address of the object calling the function to a formal parameter this in ;
Some related statements :
- this Can only be used in member functions ; Global functions or static functions cannot be used ;
- this It's a pointer constant , Always point to this object , Can't point anywhere else ;
14.4
Class related nonmember functions
If you want to call a non member function in a class , It can take the form of :
// Ordinary function
void func(xx &xcc)
{
.....
}
In class xx.h In file
void func(xx &xcc)
default Key words and delete
default keyword
Add to the class definition =default keyword , Then the default constructor can be generated ;
for example :
Time()=default;
delete
If added delete Disable a function ;
Time'()=delete;
14.5 copy constructor
- The first parameter of the class's construction parameter is the class type reference , If there are additional parameters , Then these parameters must have default values , It will be automatically called by the system at a specific time ;
Example `
Time(const Time&tmptime ,int a=3);
2. If you don't define a copy constructor , Then the system will automatically synthesize a copy constructor
边栏推荐
- Zzuli:1043 max
- [engine development] in depth GPU and rendering optimization (basic)
- Luogu p5018 [noip2018 popularization group] symmetric binary tree problem solution
- 406. 根据身高重建队列
- puzzle(016.3)千丝万缕
- Zzuli:1056 lucky numbers
- Awvs batch operation script
- [ue4] cascading shadow CSM
- Common shortcut keys in PCB
- Introduction to opengl4.0 tutorial computing shaders
猜你喜欢

How to query the baby category of tmall on Taobao

Talking about part of data storage in C language

Sub-GHz无线解决方案Z-Wave 800 系列ZG23 soc和ZGM230S模块

Dllexport and dllimport

表单文本框的使用(一) 选择文本
![Luogu p5018 [noip2018 popularization group] symmetric binary tree problem solution](/img/89/da1a3a38e02671628f385de0f30369.png)
Luogu p5018 [noip2018 popularization group] symmetric binary tree problem solution

Tonybot humanoid robot checks the port and corresponds to port 0701

Adc128s022 ADC Verilog design and Implementation

Happy capital new dual currency fund nearly 4billion yuan completed its first account closing

提高效率 Or 增加成本,开发人员应如何理解结对编程?
随机推荐
Special research report on the market of lithium battery electrolyte industry in China (2022 Edition)
Tonybot humanoid robot starts for the first time 0630
Implement Gobang with C language
[opengl] geometry shader
从书本《皮囊》摘录的几个句子
提高效率 Or 增加成本,开发人员应如何理解结对编程?
【微信小程序】WXSS 模板样式
Zzuli:1045 numerical statistics
C language dup2 function
[engine development] in depth GPU and rendering optimization (basic)
【7.3】146. LRU缓存机制
Déformation de la chaîne bm83 de niuke (conversion de cas, inversion de chaîne, remplacement de chaîne)
分布式事务(Seata) 四大模式详解
Zzuli: sum of 1051 square roots
Pytorch深度学习和目标检测实战笔记
Zzuli:1058 solving inequalities
ASTC texture compression (adaptive scalable texture compression)
FPGA blocking assignment and non blocking assignment
Zzuli:1049 square sum and cubic sum
Detailed explanation of four modes of distributed transaction (Seata)