How to use const modifier class members in C++
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