当前位置:网站首页>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
边栏推荐
- [combinatorics] permutation and combination (set combination, one-to-one correspondence model analysis example)
- Zzuli:1046 product of odd numbers
- puzzle(016.3)千丝万缕
- NOI OPENJUDGE 1.4(15)
- PHP GD image upload bypass
- PS tips - draw green earth with a brush
- US stock listing of polar: how can the delivery of 55000 units support the valuation of more than 20billion US dollars
- Pyqt interface production (login + jump page)
- How to query the baby category of tmall on Taobao
- C language dup2 function
猜你喜欢
C string format (decimal point retention / decimal conversion, etc.)
亚马逊、速卖通、Lazada、Shopee、eBay、wish、沃尔玛、阿里国际、美客多等跨境电商平台,测评自养号该如何利用产品上新期抓住流量?
表单文本框的使用(一) 选择文本
论文分享:Generating Playful Palettes from Images
[graphics] hair simulation in tressfx
Protobuf and grpc
Showmebug entered Tencent conference, opening the era of professional technical interview
[graphics] adaptive shadow map
How can entrepreneurial teams implement agile testing to improve quality and efficiency? Voice network developer entrepreneurship lecture Vol.03
Dllexport et dllimport
随机推荐
Container of symfony
C language to implement a password manager (under update)
Zzuli:1046 product of odd numbers
Bucket sorting in C language
Luogu p5018 [noip2018 popularization group] symmetric binary tree problem solution
B2020 分糖果
How to color ordinary landscape photos, PS tutorial
[ue4] HISM large scale vegetation rendering solution
Use of form text box (I) select text
Sub-GHz无线解决方案Z-Wave 800 系列ZG23 soc和ZGM230S模块
[graphics] real shading in Unreal Engine 4
Zzuli:1058 solving inequalities
复合类型(自定义类型)
Zzuli:1053 sine function
【7.3】146. LRU缓存机制
[ue4] material and shader permutation
链表有环,快慢指针走3步可以吗
Solve the problem that PR cannot be installed on win10 system. Pr2021 version -premiere Pro 2021 official Chinese version installation tutorial
adc128s022 ADC verilog设计实现
Common shortcut keys in PCB