Pointer and reference in C ++ (1)
1. pointer and reference definition
Before in-depth introduction, let's take a look at the definitions of pointers and references, the differences between pointers and references, and then discuss the differences between pointers and references in depth.
In a declaration t d where D has the form * cv-qualifier-seqopt D1 And the type of the identifier in the declaration T D1 is "derived-declarator-type-list T ", then the type of the identifier of D is "derived-declarator-type-list cv-qualifier-seq pointer to T ". the cv-qualifiers apply to the pointer and not to the object pointer.
-- Excerpt from ansi c ++ Standard
Note: Some readers may not understand cv-qualifier-seq.
CV-qualifiers (CV qualifier)
There are three types of CV-qualifiers: const-qualifier (const qualifier), Volatile-qualifier (volatile qualifier), and const-volatile-qualifier (const-volatile qualifier ).
The non-static, non-mutable, and non-referenced data members of the const class object are const-qualified;
The non-static and non-referenced data member of the volatile class object is volatile-qualified;
The non-static and non-referenced data member of the const-volatile class object is const-volatile-qualified.
When CV-qualifiers is used to limit the array type, the array member is actually limited by the CV-qualifiers instead of the array type.
The composite type is not limited by the CV-qualifier because its members are limited by the CV-qualifier. That is to say, even if the composite type members are limited by the CV-qualifier, this composite type is not a CV-qualified object.
In a declaration t d where D has the form & D1 And the type of the identifier in the declaration T D1 is "derived-declarator-type-list T ", then the type of the identifier of D is "derived-declarator-type-list cv-qualifier-seq reference to T ". cv-qualified references are ill-formed when T when the cv-qualifiers are introduced through the use of a typedef or a template type argument, in which case the cv-qualifiers are ignored.
-- Excerpt from ansi c ++ Standard
The above definition is hard to understand. If so, it means you are not familiar with C ++, and you still have a long way to go. The following is a brief introduction:
-
Pointer-for a type T, T * is the pointer type pointing to T, that is, a T * type variable can save the address of a T object, type T can be added with some restrictions, such as const and volatile. See the following figure for pointer meanings: