c ++ Primer first chapter combing knowledge

1, in order to support separate compilation, we will declare and define separate. If you want to just declare a variable rather than define it, as long as a plus in front of the variable extern, but do not give it to initialize. Initialization means defining offset the effect of extern. Variables can be defined only once, but many times do not declare. In the functions that initialize a variable with extern keyword if, it will error.

2, a reference that is an alias, reference is not an object, on the contrary, he was just another name for the object. A reference assignment, in fact, the value assigned to the object reference bound; obtaining a reference value, in fact, it is to get the value of the object reference bound. Because the reference is not an object, it can not be defined cited references.

3, C ++ programs nullptr preferably used to initialize the pointer is a null pointer, at the same time avoid using NULL. Any non-zero value condition corresponding to the pointer is true. Such as: int * pi = 1; if (pi) if true. Also == pointer can be used to compare whether want to wait. * & Defined generally and when a pointer or reference variable should be written with variable names, such as: int * a;

4, by default, const objects do effectively within the file. const variable must be initialized in the case without modification. Const object of the operation there is a initialization, if the use of an object to initialize another object, they are not constant const does not matter.

1      you i = 20,190,227 ;
2      const  you ci = i;
3      you ii = ci;

If the initial value of the const variable is not a constant expression, and we want to define a file and want to use on the need to meet the definition of extern add keywords in different files. In front of the stated increase the role also is to be shared between different files. So, if you want to share files between multiple const object, you must add extern keyword before the variable definition.

Usually this constant pointer write: int * const i = & a;

5, type alias, traditional typedef we use, such as:  typedef Double du;  we can use, C ++ 11 defines a new keyword by using du instead of double, his role with the typedef is the same, but also to type the name of the individual to take  a using Double du; 

Guess you like

Origin www.cnblogs.com/xiaodangxiansheng/p/11139236.html