当前位置:网站首页>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
边栏推荐
- [graphics] real shading in Unreal Engine 4
- puzzle(016.4)多米诺效应
- Introduction to opengl4.0 tutorial computing shaders
- Talking about part of data storage in C language
- Tonybot Humanoïde Robot Infrared Remote play 0630
- FPGA blocking assignment and non blocking assignment
- Write a 2-minute countdown.
- Tensor 省略号(三个点)切片
- Four data flows and cases of grpc
- 创业团队如何落地敏捷测试,提升质量效能?丨声网开发者创业讲堂 Vol.03
猜你喜欢

ASTC texture compression (adaptive scalable texture compression)
![[ue4] material and shader permutation](/img/8f/7743ac378490fcd7b9ecc5b4c2ef2a.jpg)
[ue4] material and shader permutation

C string format (decimal point retention / decimal conversion, etc.)

dllexport和dllimport

Showmebug entered Tencent conference, opening the era of professional technical interview

tonybot 人形机器人 红外遥控玩法 0630

Devaxpress: range selection control rangecontrol uses

Implement Gobang with C language
![[graphics] real shading in Unreal Engine 4](/img/8d/53775c7570c5578f4fe985592bb305.jpg)
[graphics] real shading in Unreal Engine 4
![[engine development] in depth GPU and rendering optimization (basic)](/img/71/abf09941eb06cd91784df50891fe29.jpg)
[engine development] in depth GPU and rendering optimization (basic)
随机推荐
Zzuli:1045 numerical statistics
Pytorch深度学习和目标检测实战笔记
复合类型(自定义类型)
Tonybot humanoid robot checks the port and corresponds to port 0701
retrofit
Open under vs2019 UI file QT designer flash back problem
洛谷P3065 [USACO12DEC]First! G 题解
Talking about part of data storage in C language
tonybot 人形机器人 红外遥控玩法 0630
[ue4] HISM large scale vegetation rendering solution
Qt—绘制其他东西
China PETG market forecast and Strategic Research Report (2022 Edition)
Tonybot humanoid robot infrared remote control play 0630
Zzuli:1047 logarithmic table
US stock listing of polar: how can the delivery of 55000 units support the valuation of more than 20billion US dollars
CentOS7部署哨兵Redis(带架构图,清晰易懂)
Vs+qt multithreading implementation -- run and movetothread
[ue4] geometry drawing pipeline
PHP GD image upload bypass
Paper sharing: generating playful palettes from images