Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use const modifier class members in C++

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you how to use const embellishments in C++, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!

# include

# include

# include

# include

Using namespace std

/ *

A1 const modifies a member variable in a class, then the variable must be initialized with an initialization list.

A2 const modifies a member function in a class, indicating that the member function does not modify all member variables in the class.

When A3 const modifies a reference to a function input parameter, it means that the content of the reference must not change in this function.

A3.1 when const modifies the "reference input parameter" of a function, the function can only use the member functions of the const of the input parameter.

, /

Class Student {

String m_name

Const int masks; / / A1

Int m_score

Public:

Int show_info_no_const (void)

{

Cout

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report