当前位置:网站首页>Summary of const type data
Summary of const type data
2022-07-24 10:54:00 【Linux programming school】
This section introduces const Type data and references , They can be used to protect shared data . The following is a summary of several const The usage and difference of type data , Suppose there is student class .
(1) studentconst stud; perhaps conststudent stud;
Express stud It's a regular object , Its value cannot be changed under any circumstances .
(2) voidstudent::func() const
Express func() The function is student Class , You can reference , however , Member variables in this class cannot be modified .
(3) student* const ps;
Express ps It's a student Pointer to type , Is a constant pointer , therefore , The pointer cannot be modified ps Value . however , You can modify ps The pointer points to the data of the object .
(4) const student* ps;
Express ps It's a student Pointer to type , It refers to a constant object . therefore , Cannot be modified ps Data pointing to the object . however , You can modify ps Pointer value .
(5) const student& stud = s;
Express stud It's a reference , quote s object . And it often refers to objects . therefore , Cannot be modified stud Reference the data of the object .
8 summary
This chapter introduces C++ Data protection of class objects , This knowledge point reflects the “ encapsulation 、 Protect ” characteristic , An object can have private data , Data that can not be modified .
that ,C++ Provides const keyword , It can effectively protect the security of data . therefore , In the design of many functions , In order to protect the security of data , Can be defined as const type . Good at using const data type , It can effectively protect the security of data .
Readers should carefully analyze , Master every knowledge point , then , Summarize your understanding of this knowledge point . The knowledge summarized by myself , Understanding is profound , Is the knowledge you have mastered .
Wei Kaifeng Linux C/C++ Programming tutorial ,Linux System programming ,Openwrt System development , WeChat :13926572996,QQ:1523520001, Blog :www.mylinux.vip
边栏推荐
- 火山引擎:开放字节跳动同款AI基建,一套系统解决多重训练任务
- [interview: Basics 05: quick sort]
- Five best WordPress advertising plug-ins
- 「低功耗蓝牙模块」主从一体 蓝牙嗅探-助力智能门锁
- [FPGA]: IP core --divider (divider)
- binlog、iptables防止nmap扫描、xtrabackup全量+增量备份以及redlog和binlog两者的关系
- 分布式事务处理方案大 PK!
- Zero basic learning canoe panel (7) -- input/output box
- How to gracefully realize idempotency and distributed current limiting of distributed interfaces (glory Collection Edition)
- Real time weather API
猜你喜欢

Qt创建应用程序托盘及相关功能

零基础学习CANoe Panel(5)——改变变量的值,控件图像也改变,这是怎么回事?

QT create application tray and related functions

Google cooperates with colleges and universities to develop a general model, proteogan, which can design and generate proteins with new functions

read_ CSV error: 'GBK' codec can't decode byte 0xb4 in position 274: illegal multibyte sequence

App automation and simple environment construction
![[AHK] AutoHotKey tutorial ①](/img/70/20f2e19e3e268ffe2f1e2956719c09.png)
[AHK] AutoHotKey tutorial ①

简单使用 MySQL 索引

Cookie sessionstorage localstorage differences

【直播报名】Location Cache 模块浅析及 OCP 监控、报警详解
随机推荐
563页(30万字)智慧化工园区(一期)总体设计方案
Tidb query SQL report runtime error: index out of range [-1] error
PC Museum (1) 1970 datapoint 2000
每日三题 7.21
[FPGA]: IP core -- xadc
实时天气API
When to use obj['attribute name'] for the attribute name of an object
Disk storage chain B-tree and b+ tree
Five network IO models
Machine learning quiz (10) using QT and tensorflow to create cnn/fnn test environment
App automation and simple environment construction
Zero basic learning canoe panel (7) -- input/output box
Is it safe to open an online stock account?
Qt创建应用程序托盘及相关功能
MySQL - update data records in tables
火山引擎:开放字节跳动同款AI基建,一套系统解决多重训练任务
Detailed explanation of Flink operation architecture
谷歌联合高校研发通用模型ProteoGAN,可设计生成具有新功能的蛋白质
web咸鱼自救攻略--typescript的类没有你想象中的那么难
Zero basic learning canoe panel (7) -- file selection (pathdiaglog)