当前位置:网站首页>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
边栏推荐
- 556. 下一个更大元素 III : 简单构造模拟题
- [graphics] hair simulation in tressfx
- Bucket sorting in C language
- 分布式事务(Seata) 四大模式详解
- PS tips - draw green earth with a brush
- How can entrepreneurial teams implement agile testing to improve quality and efficiency? Voice network developer entrepreneurship lecture Vol.03
- 洛谷P4047 [JSOI2010]部落划分 题解
- Zzuli:1055 rabbit reproduction
- 【7.3】146. LRU caching mechanism
- Vs+qt application development, set software icon icon
猜你喜欢

puzzle(016.3)千丝万缕

On MEM series functions of C language
![[ue4] cascading shadow CSM](/img/83/f4dfda3bd5ba0172676c450ba7693b.jpg)
[ue4] cascading shadow CSM
![[graphics] adaptive shadow map](/img/93/a6a3c7716331368c90c2c86da11f55.jpg)
[graphics] adaptive shadow map

Solve the problem that PR cannot be installed on win10 system. Pr2021 version -premiere Pro 2021 official Chinese version installation tutorial

Devaxpress: range selection control rangecontrol uses

远程服务器后台挂起 nohup

C language to realize mine sweeping

Vs+qt multithreading implementation -- run and movetothread

【微信小程序】WXSS 模板样式
随机推荐
.NET六大设计原则个人白话理解,有误请大神指正
Plane vector addition
Déformation de la chaîne bm83 de niuke (conversion de cas, inversion de chaîne, remplacement de chaîne)
Timecho of Tianmou technology completed an angel round financing of nearly 100 million yuan to create a native timing database of the industrial Internet of things
Zzuli:1058 solving inequalities
[opengl] bone animation blending effect
Simulation of LS -al command in C language
7-9 one way in, two ways out (25 points)
[opengl] advanced chapter of texture - principle of flowmap
Time conversion ()
[engine development] in depth GPU and rendering optimization (basic)
Amazon, express, lazada, shopee, eBay, wish, Wal Mart, Alibaba international, meikeduo and other cross-border e-commerce platforms evaluate how Ziyang account can seize traffic by using products in th
【微信小程序】WXSS 模板样式
QT - draw something else
Solve the problem that PR cannot be installed on win10 system. Pr2021 version -premiere Pro 2021 official Chinese version installation tutorial
Zzuli:1049 square sum and cubic sum
Zzuli:1057 prime number determination
Sub-GHz无线解决方案Z-Wave 800 系列ZG23 soc和ZGM230S模块
Qt development - scrolling digital selector commonly used in embedded system
NOI OPENJUDGE 1.5(23)