Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use const modifier class members in C++

Shulou Source: shulou.com Published: 2022-06-02 11:29:19 10月01日 Update

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

Tags: Functions members content variables articles articles necessary not so much reasons most of them actually that is properties situations more knowledge industry information information channels. Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS NVidia OPPO Reno Shulou Tech Info Microsoft