-
1) The const object calls the st member function.
2) Non-const member functions can call const member functions, which are generally used to avoid duplication, but introduce a casting action.
3) Details can be referred to:
effective
c++(3e)
p24 supplement.
4) The Chinese version, the one translated by Hou Jie, I turned the book to yours.
-
Constant member functions cannot change the private or public data defined in the class.
Unless you add mutable.
The const data member can be entered by the user in the main function.
The premise is to initialize in the constructor.
#include
usingnamespace
std;class
boxprivate
constint
height;
mutable
intwidth;
intlength;
public:
box(const
inth=10,int
w=2,int
l=3):height(h),width(w),length(l){}
voiddisplay()
const;
voidbox::display()
constwidth=width*2;
cout<
a>>b>>c;
boxb1(a,b,c);
Let me give you a simple example.
-
To put it simply: CONST represents read-only variables in C and constants in C++.
C is the abbreviation of constant, which means constant and unchanging, and is also translated as constant, but many people think that the values modified by const are constants, but this is actually inaccurate. Because, to be precise, a read-only variable, its value cannot be used at compile time, because the compiler does not know what it stores at compile time. Maybe this keyword should have been replaced with readonly
In C, the variables defined by the const only give the corresponding memory address, not the immediate number as in define, so the read-only variables defined by const have only one backup during the program run (because it is a global read-only variable and stored in the static area), while the macro variables defined by define have several backups in memory.
C++ language:
Constant type refers to the type specified by the type modifier const that cannot be updated.
C++ was originally introduced to replace the precompile directive, eliminating its shortcomings while inheriting its advantages. "Disadvantages: It is only the substitution of simple values and **, the lack of type detection mechanism, and the safety is not good; There are three advantages:
1.Avoid the appearance of ambiguous numbers and clarify the semantics of the program2Convenient parameter adjustment and modification, 3
Improve the efficiency of program execution, as there is no need to allocate space for constants
What non-enterprise questions have questions, I can introduce you to the bidding promotion. >>>More
Find out why students don't complete their assignments and solve the problem. >>>More
Even if it is carried out, it will be carried out in Scarborough Shoal and the Philippines itself, and the impact on our country will be minimal, and even in the southeastern coastal areas, there will be sufficient military strength to protect the safety of the people, and naval warfare, air warfare, and landing warfare are the main forms.
The four-stage Taijiquan, also known as the 32-style Taijiquan, is a set of comprehensive Taijiquan based on the Yang style combined with other forms. Among them: 1, the right "press" type of the bird's tail is Wu style, 2, the progress of moving the block is the Sun style, 3, the right kick is the Chen style, 4, the left and right shuttle is the Wu style, 5, the lower potential is the Wu style, 6, the golden rooster independence is the martial style. >>>More
Conventional C10, C15, C20, C25, C30 concrete mix such as the figure below. >>>More