Global Variables:
Class, outside of the method, the class directly write NSString * str = @ "xxx"; STR is a global variable (object oriented, to use global variables, generally set as properties of the Class)
Local Variables:
Variables written
RegisterA variable declared with register is called a register variable, which is stored directly in the register of the machine, if possible, but not for the four-bit compiler when the global When optimizations(global Optimization) is on, it makes
C ++ class const, static, static const member variables# Include
Using namespace std;
Class Test
{
Private:
Const int a; // The const member variable can only be initialized in the constructor member initialization list,
Use of phpself, $ this, const, static,-& amp; gt. Summary. When the internal method of the class accesses the attributes declared as const and static, use the form of self ::$ name. Note that the declarative format of the const attribute is constPI3.
1. What does the keyword const mean?Const int A; int Const A; Const int *A; int Const *A; int Const A; int Const Const A;The first two functions are the same: A is a constant integer numberThe third and fourth means: A is a pointer to a constant
Come to the conclusion today.
, when accessing properties declared as const and static in the inner method of a class, use Self:: $name form. Note that the Const attribute's declaration format, const PI=3.14, is not const $PI =3.14
Copy the Code
If the method of the class is static, the properties that he accesses must also be static., when the internal method of the class accesses properties that are not declared const and static, use $this->value = ' class_a ';Class Clss_a {private static
One, const
1. In the definition of variable
(1) const int a=10;
Description: The defined int type variable A cannot be modified and can only be used. A variable with the Const keyword can be defined as a global variable, but at this point the global
Const:
1. Define variables. You can write the following statements:
Type const valuename = value;Const type valuename = value;
2. When used as a global variable and in other files: (by default, const is local)
1. cpp: extern const type valuename =
Now let's look at the following equivalence relationships:
Static in C # and static in Java
Simple. The two are used in the same way. The following two aspects are discussed:
1.Variables belong to the class, not the instance level. It can only be
Summary.When the internal method of the class accesses the attributes declared as const and static, use the form of self ::$ name. Note the declarative format of the const attribute. const PI = 3.14 instead of const $ PI = 3.14.Copy codeThe Code is
Const defines a static value that is often assigned during object initialization. It cannot be changed later. It is a compilation constant.
Static defines a Static variable. You can change its value externally ..
Readonly is a read-only variable. It
1. Const usage:Why use const?Code written using symbolic constants is easier to maintain. Pointers are often moved while reading, rather than writing. Many function parameters are read-only and not written. The most common use of const is as the
Come to the conclusion today.
, when accessing properties declared as const and static in the inner method of a class, use Self:: $name form. Note that the Const attribute's declaration format, const PI=3.14, is not const $PI =3.14
Copy CodeThe
I read the discussion about pointers and references on the Internet today, and I have a bit of understanding. The record is as follows.
It is introduced in C ++ when it is referenced. It is essentially a pointer and is a special pointer.
1) It
Summary.
When the internal method of the class accesses the attributes declared as const and static, use the form of Self ::$ name. Note the declarative format of the const attribute. Const Pi = 3.14 instead of const $ Pi = 3.14.
CopyCodeThe Code
First, the constIn C + +:1, Constant object: the creation of the object when the Const keyword, the object can not be modified, there is a constant attribute, it means that the entire object all variables cannot be changed2, the normal object cannot
Come to the conclusion today.
, when the internal method of a class accesses a property that has been declared as const and static, use the self:: $name form. Note The Const attribute's declaration format, const pi=3.14, not const $PI =3.14
first part macro definition
Syntax format for macro definition: #define Example 1: Use #define to implement macros and find the maximum value.
#define MAX ((x) > (y)) (X,y) (x):(y))
Note in the macro you need to carefully enclose the
"1" Static:
1 Limit the scope of a variable or function
2 Set the storage domain of the variable
Common to have:
(1) static global variable (2) static local variable (3) static function
(1) Static global variable: 1,static global variable is only
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.