Please don't reprint this article; please don't re-publish in any form; please delete it within 24 hours of downloading this article; it is forbidden to use this article for commercial purposes.
3 Basic Concepts [Basic] 3.3 Declarative Regions and scopes [Basic.Scope] 3.3.6 Class Scope [Basic.Scope.class] 3 Basic Concepts [Basic] 3.3 Define Areas and Scope [Basic. Scope] 3.3.6 Scope [Basic. Scope. Class] The Following Rules Describe The Scope of Names Declared In Classes.
The potential scope of a name declared in a class consists not only of the declarative region following the name's declarator, but also of all function bodies, default arguments, and constructor ctor-initializers in that class (including such things in nested classes). A name N used in a class S shall refer to the same declaration in its context and when re-evaluated in the completed scope of S. No diagnostic is required for a violation of this rule. If reordering member declarations in a class yields an alternate valid program under 1 and 2, the program is ill-formed, no diagnostic is required. A name declared within a member function hides a declaration of the same whose scope extends to or past the end of the member function's class. The potential scope of a declaration that extends to or past the end of a class definition also extends to the regions defined by its member definitions, even if the members are defined lexically outside the class (this includes static data member defi nitions, nested class definitions, member function definitions (including the member function body and, for constructor functions (12.1), the ctor-initializer (12.6.2)) and any portion of the declarator part of such definitions which follows the identifier, including A parameter-declaration-clause and any default arguments (8.3.6). [EXAMPLE: TYPEDEF INT C; Enum {i = 1}; class x {char v [i]; // error: I Refers to :: I / / but when {c);} // ok: x :: c char C;} // ok: x :: c;} // ok: x :: c;}; typef char * t; struct y {t a;
// error: t refers to :: t // but when it is y :: t typedef long t; t;}; typedef INT i; class d {typef Ii; // error, evenugh no repord involved}; --end example] The following rules describe the scope of the name declared in the class. The potential scope of the name declared in the class includes not only the declaration area behind its declarators, but also all of the functional bodies, default parameters, and CTOR-initializers of the constructor, including the corresponding thing of the nesting. . The name N application in class S is declaration referred to in its context, and the declaration reselected when the Scope of S is completed. Violation of this rule does not need to diagnose. If in Rule 1 and 2, a member declaration of a class declare that a different legitimate process is generated, and the program is a pathological form and does not need to diagnose. In the name of the member function, the hidden scope is the same as the same name after the end of this member function, or the same name after the end. The potential scope of the declaration outside or after the class definition is also outside the member definition of the class, regardless of whether these members are defined in the lexical (these members include static data member definitions, nested class definitions, member function definitions (Including the CTOR-initializer (12.6.2)) of the member function body and constructor (12.1)), or any declaration portion behind this identifier, including parameters - declaration - clauses, and any default arguments (8.3. 6) Outside. [Example: typedef int C; Enum {i = 1}; class x {char v [i]; // error: i Refers to :: I // But when reassessment, it will be x: : I Int f () {Return SizeOf (c);} // correct: x :: c char C; enum {i = 2};}; typedef char * t; struct y {t a; // error: t Refers to :: t // but will be Y :: t typedef long t; t b;}; typef II; // error, even without rearrangement}; - Example] The name of a class member shall Only BE Used As Follows:
in the scope of its class (as described above) or a class derived (clause 10) from its class, after the. operator applied to an expression of the type of its class (5.2.5) or class derived from its class, after the -> operator applied to a pointer to an object of its class (5.2.5) or a class derived from its class, after the :: scope resolution operator (5.1) applied to the name of its class or a class derived from its Class. The name of the class member can only be used in accordance with the following case: the scope of the scope of the class (as described above) or a derived (chapter 10) from the class of the class, or derived The type of expression (5.2.5) of the type of this class is behind, after applying to this class, or derived from the pointer (5.2.5) of the class object from the class, Apply to this class, or derived from the :: Scope parsing operator (5.1) from the class name of the class. Prev [Basic.Scope.namespace] | Next [Basic.Scope.hiding] Previous [Basic. Scope. Name Space] | Next Page [Basic. Scope. Hide]