当前位置:网站首页>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
边栏推荐
猜你喜欢

提高效率 Or 增加成本,开发人员应如何理解结对编程?

Vs+qt application development, set software icon icon

Vs+qt multithreading implementation -- run and movetothread

C # realizes the login interface, and the password asterisk is displayed (hide the input password)

Introduction to opengl4.0 tutorial computing shaders

retrofit

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

How can entrepreneurial teams implement agile testing to improve quality and efficiency? Voice network developer entrepreneurship lecture Vol.03

Open under vs2019 UI file QT designer flash back problem

B2020 分糖果
随机推荐
Luogu p3065 [usaco12dec]first! G problem solution
Container of symfony
NOI OPENJUDGE 1.6(09)
[engine development] rendering architecture and advanced graphics programming
.NET六大设计原则个人白话理解,有误请大神指正
pyQt界面制作(登录+跳转页面)
Piwigo 2.7.1 sqli learning
创业团队如何落地敏捷测试,提升质量效能?丨声网开发者创业讲堂 Vol.03
Table of mathematical constants by q779
7-3 count the number of words in a line of text
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
C language memory function
[ue4] geometry drawing pipeline
Talking about part of data storage in C language
Puzzle (016.3) is inextricably linked
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
My QT learning path -- how qdatetimeedit is empty
Zhejiang University Edition "C language programming (4th Edition)" topic set reference ideas set
556. 下一个更大元素 III : 简单构造模拟题
Tonybot Humanoïde Robot Infrared Remote play 0630