当前位置:网站首页>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
边栏推荐
- FPGA blocking assignment and non blocking assignment
- tonybot 人形機器人 紅外遙控玩法 0630
- Plane vector addition
- Zzuli:1047 logarithmic table
- 556. 下一个更大元素 III : 简单构造模拟题
- Luogu p5536 [xr-3] core city solution
- .NET六大设计原则个人白话理解,有误请大神指正
- Zzuli: cumulative sum of 1050 factorials
- 洛谷P4047 [JSOI2010]部落划分 题解
- Bucket sorting in C language
猜你喜欢

Protobuf and grpc

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

Frequently asked questions: PHP LDAP_ add(): Add: Undefined attribute type in

Zhonggan micro sprint technology innovation board: annual revenue of 240million, net loss of 17.82 million, proposed to raise 600million

复合类型(自定义类型)

PS tips - draw green earth with a brush

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

Four data flows and cases of grpc

Puzzle (016.3) is inextricably linked

Tonybot humanoid robot checks the port and corresponds to port 0701
随机推荐
牛客 BM83 字符串变形(大小写转换,字符串反转,字符串替换)
Zzuli: sum of 1051 square roots
puzzle(016.4)多米诺效应
[engine development] rendering architecture and advanced graphics programming
Zzuli:1049 square sum and cubic sum
Zzuli:1048 factorial table
556. 下一个更大元素 III : 简单构造模拟题
ASTC texture compression (adaptive scalable texture compression)
Detailed explanation of four modes of distributed transaction (Seata)
洛谷P4047 [JSOI2010]部落划分 题解
【微信小程序】WXSS 模板样式
[ue4] HISM large scale vegetation rendering solution
[opengl] face pinching system
[graphics] adaptive shadow map
The latest M1 dedicated Au update Adobe audit CC 2021 Chinese direct installation version has solved the problems of M1 installation without flash back!
Joomla! CMS 3.0~3.4.6 RCE
The picture quality has been improved! LR enhancement details_ Lightroom turns on AI photo detail enhancement: picture clarity increases by 30%
Detailed explanation of four modes of distributed transaction (Seata)
How to color ordinary landscape photos, PS tutorial
7-9 one way in, two ways out (25 points)