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 Declara Tor, but also of the all function bodies, default arguments, and constructor ctor-initializers in that class (including such t Hings in nested classes). A name N used in a class S shall refer to the same declaration in it 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, n o 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 mem ber 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 def ined by it member definitions, even if the members is defined lexically outside the class (this includes static data mem BER definitions, nested class definitions, member function definitions (including the member function body and, for CONSTR Uctor functions (12.1), the Ctor-initializer (12.6.2)) and any portion of the declarator part of such definitions which FO Llows 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 Reevaluated was x::i int F () {return sizeof (c);} Ok:x::c char c; enum {i = 2}; };
typedef char* T; struct Y { T A; Error:t refers to:: T But when Reevaluated was y::t typedef long T; T b; };
typedef int I; Class D { typedef i I; Error, even though no reordering involved }; --end Example] |
The following rules describe the scope of the names declared in the class. The potential scope of a name declared in a class includes not only the declaration area following its declarator, but also all the body of the class, the default parameters, and the ctor-initializer for the constructor, including the corresponding object of the nested class. The name N applied in the class S is the declaration that is referred to in its context, and the claims that are re-evaluated when the scope of S is completed should be the same. No diagnosis is required to violate this rule. If, under rules 1 and 2, a member declaration of a class is rescheduled to produce a different legitimate program, the program is ill-structured and does not require a diagnosis. The name declared in the member function hides the declaration of the same name beyond the class where the scope is a member function, or after the end. The potential scope of declarations outside or after the class definition is also outside the member definition of the class, regardless of whether those members are lexical defined in the class (these members include static data member definitions, nested class definitions, member function definitions (including member function bodies and constructors (12.1) ctor-initializer (12.6.2)), or any outside of the declarator section following the identifier, including the 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 the reassessment is made, 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 when the reassessment is made, it will be y::t typedef long T; T b; };
typedef int I; Class D { typedef i I; Error, even if it's not rescheduled }; --End of case " |
The name of a class member shall only is used as follows:in the scope of its class (as described above) or a class derive D (clause) from their class, after the. Operator applied to a expression of the type of its classes (5.2.5) or class derived from their class, after the and Operat or applied to a pointer-a 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 their class or a class derived from its class. |
The name of a class member can only be used if the scope of its class (as described above) or a derivation (section 10) is applied to the class, or to an expression (5.2.5) of the type that derives from the class, from the scope of the class. operator, after an operator that is applied to a pointer to the class, or to a class object derived from the class (5.2.5), after the: scope resolution operator (5.1) applied to the class, or derived from the class name. |