C ++ const and const
The usage of the const keyword in C ++ is very flexible, and the use of const will greatly improve the robustness of the program. I will summarize the following information based on various aspects and hope to help my friends.
Keyword of c -- const comprehension and usage Author: lj_860603 views: 21106 Article Source: site original Release Date:-7-1 Comments (21)
Enter the original post discussion: http://bbs.bccn.net/thread-66030-1-1.html
Understanding and usage of const,
I have always thought that the final keyword of Java is similar to the const keyword of C ++. Through more in-depth study of C ++, I gradually learned some of their differences.
1. The final of Java can modify the class. Although the const of C ++
The const keyword does not represent a constant, but "the content cannot be modified ". The variable modified by const does not necessarily have the same value. It may be changed by external conditions that cannot be detected by the compiler. Const
C #: const and readonlyTo sum up const and readonly:
The const and readonly values can no longer be rewritten once initialized;Const can only be initialized at Declaration; readonly can be initialized at Declaration or in constructor;Const implies
What does the following statement mean?const int A;int const A;const int *a;int * const A;int const * a const;1, A is a constant number of plastic2, A is a constant number of plastic3, A is a pointer to the number of normal shaping (the number of
Tagged with: C + + LinuxConst is decorated with a variable before it: The variable pointed to by the pointer is const, that is, the variable cannot be modified by the pointerThe const is placed after the pointer is decorated: the pointer itself can
Because the const object cannot be changed once it has been created, the const object must be initialized .
const int i = foo (); Run-time initialization
const int J = 1; Compile-time initialization
If you initialize another object with
Initialize:The Const object must be initialized once its value cannot be changed once it is created.scope: The default const object is valid only within a file. Exception:extern constconstant Reference: the object that is bound cannot be modified by
the class's member function is followed by a const, which indicates that the function does not make any changes to the data members of the class object (accurately, non-static data members) .When designing a class, one principle is to add a const to
The use of the Const keyword in C + + is very flexible, and using the const will greatly improve the robustness of the program, I found in various aspects of the information summarized below, hoping to help friends.Const is a type modifier commonly
The use of the Const keyword in C + + is very flexible, and using the const will greatly improve the robustness of the program, I found in various aspects of the information summarized below, hoping to help friends.Const is a type modifier commonly
When you declare a variable to be const in the C source code file, you can do so in the following ways:
const int i = 2;
You can then use this variable in another module, which is indicated as follows:
extern const int i;
But to
1. by Default,constObjects is Local to a FileBy default, the const object is localThis is the original in "C + + primary 5th."When a const object was initialized from a Compile-time constant, such asDefinition of BufSize:
Const int
Const type definition: Indicates that the value of a variable or object cannot be updated, and is introduced to replace precompiled directives
Constants must be initialized *************************
The role of Cons
(1) You can define const
Turn from: http://blog.csdn.net/feixiaoxing/article/details/6786622
Const is a key word in C + + language, but if used well, it can greatly improve the robustness of the code. In general, the use of const is still quite a lot of places, but mainly
C + + In the use of the Const keyword is very flexible, and using the const will greatly improve the robustness of the program, I based on all aspects of the information to summarize the following, I hope to help friends.
Const is a commonly used
Const repost Summary
The connection cannot be found. Sorry...
When you see the const keyword, C ++ programmers may first think of const constants. This is not a good conditioned reflection. If you only know that the constant is defined with const,
I recently learned C ++ and used the copy constructor to raise some questions.
1 Class Test { 2 Private : 3 Int A; 4 Public : 5 Test (); 6 Test ( Const Test &T ){ 7 A = T.; 8 }; 9 ~ Test (); 10 Int Getdate (); /
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.