tmp/tmp1rz7px8f/{from.md → to.md}
RENAMED
|
@@ -1,12 +1,12 @@
|
|
| 1 |
### Static members <a id="class.static">[[class.static]]</a>
|
| 2 |
|
| 3 |
A static member `s` of class `X` may be referred to using the
|
| 4 |
*qualified-id* expression `X::s`; it is not necessary to use the class
|
| 5 |
-
member access syntax
|
| 6 |
-
|
| 7 |
-
|
| 8 |
|
| 9 |
[*Example 1*:
|
| 10 |
|
| 11 |
``` cpp
|
| 12 |
struct process {
|
|
@@ -21,15 +21,15 @@ void f() {
|
|
| 21 |
```
|
| 22 |
|
| 23 |
— *end example*]
|
| 24 |
|
| 25 |
A static member may be referred to directly in the scope of its class or
|
| 26 |
-
in the scope of a class derived
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
|
| 32 |
[*Example 2*:
|
| 33 |
|
| 34 |
``` cpp
|
| 35 |
int g();
|
|
@@ -42,59 +42,53 @@ struct Y : X {
|
|
| 42 |
int Y::i = g(); // equivalent to Y::g();
|
| 43 |
```
|
| 44 |
|
| 45 |
— *end example*]
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
[[basic.lookup.unqual]]) finds that the *unqualified-id* refers to a
|
| 50 |
-
static member, enumerator, or nested type of the member’s class (or of a
|
| 51 |
-
base class of the member’s class), the *unqualified-id* is transformed
|
| 52 |
-
into a *qualified-id* expression in which the *nested-name-specifier*
|
| 53 |
-
names the class scope from which the member is referenced.
|
| 54 |
-
|
| 55 |
-
[*Note 1*: See [[expr.prim]] for restrictions on the use of non-static
|
| 56 |
-
data members and non-static member functions. — *end note*]
|
| 57 |
-
|
| 58 |
-
Static members obey the usual class member access rules (Clause
|
| 59 |
-
[[class.access]]). When used in the declaration of a class member, the
|
| 60 |
`static` specifier shall only be used in the member declarations that
|
| 61 |
appear within the *member-specification* of the class definition.
|
| 62 |
|
| 63 |
-
[*Note
|
| 64 |
namespace scope. — *end note*]
|
| 65 |
|
| 66 |
#### Static member functions <a id="class.static.mfct">[[class.static.mfct]]</a>
|
| 67 |
|
| 68 |
[*Note 1*: The rules described in [[class.mfct]] apply to static
|
| 69 |
member functions. — *end note*]
|
| 70 |
|
| 71 |
-
[*Note 2*: A static member function does not have a `this` pointer
|
| 72 |
-
[[class.this]]
|
| 73 |
|
| 74 |
A static member function shall not be `virtual`. There shall not be a
|
| 75 |
static and a non-static member function with the same name and the same
|
| 76 |
-
parameter types
|
| 77 |
declared `const`, `volatile`, or `const volatile`.
|
| 78 |
|
| 79 |
#### Static data members <a id="class.static.data">[[class.static.data]]</a>
|
| 80 |
|
| 81 |
A static data member is not part of the subobjects of a class. If a
|
| 82 |
static data member is declared `thread_local` there is one copy of the
|
| 83 |
member per thread. If a static data member is not declared
|
| 84 |
`thread_local` there is one copy of the data member that is shared by
|
| 85 |
all the objects of the class.
|
| 86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
The declaration of a non-inline static data member in its class
|
| 88 |
definition is not a definition and may be of an incomplete type other
|
| 89 |
than cv `void`. The definition for a static data member that is not
|
| 90 |
defined inline in the class definition shall appear in a namespace scope
|
| 91 |
enclosing the member’s class definition. In the definition at namespace
|
| 92 |
scope, the name of the static data member shall be qualified by its
|
| 93 |
class name using the `::` operator. The *initializer* expression in the
|
| 94 |
-
definition of a static data member is in the scope of its class
|
| 95 |
-
[[basic.scope.class]]
|
| 96 |
|
| 97 |
[*Example 1*:
|
| 98 |
|
| 99 |
``` cpp
|
| 100 |
class process {
|
|
@@ -130,33 +124,26 @@ of class `process` are created by the program.
|
|
| 130 |
— *end note*]
|
| 131 |
|
| 132 |
If a non-volatile non-inline `const` static data member is of integral
|
| 133 |
or enumeration type, its declaration in the class definition can specify
|
| 134 |
a *brace-or-equal-initializer* in which every *initializer-clause* that
|
| 135 |
-
is an *assignment-expression* is a constant expression
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
*brace-or-equal-initializer*. If the member is declared with the
|
| 141 |
`constexpr` specifier, it may be redeclared in namespace scope with no
|
| 142 |
-
initializer (this usage is deprecated; see [[depr.
|
| 143 |
Declarations of other static data members shall not specify a
|
| 144 |
*brace-or-equal-initializer*.
|
| 145 |
|
| 146 |
-
[*Note 2*: There
|
| 147 |
-
|
| 148 |
-
is required. — *end note*]
|
| 149 |
-
|
| 150 |
-
Unnamed classes and classes contained directly or indirectly within
|
| 151 |
-
unnamed classes shall not contain static data members.
|
| 152 |
|
| 153 |
[*Note 3*: Static data members of a class in namespace scope have the
|
| 154 |
-
linkage of
|
| 155 |
-
static data members ([[class.local]]). — *end note*]
|
| 156 |
|
| 157 |
Static data members are initialized and destroyed exactly like non-local
|
| 158 |
variables ([[basic.start.static]], [[basic.start.dynamic]],
|
| 159 |
[[basic.start.term]]).
|
| 160 |
|
| 161 |
-
A static data member shall not be `mutable` ([[dcl.stc]]).
|
| 162 |
-
|
|
|
|
| 1 |
### Static members <a id="class.static">[[class.static]]</a>
|
| 2 |
|
| 3 |
A static member `s` of class `X` may be referred to using the
|
| 4 |
*qualified-id* expression `X::s`; it is not necessary to use the class
|
| 5 |
+
member access syntax [[expr.ref]] to refer to a static member. A static
|
| 6 |
+
member may be referred to using the class member access syntax, in which
|
| 7 |
+
case the object expression is evaluated.
|
| 8 |
|
| 9 |
[*Example 1*:
|
| 10 |
|
| 11 |
``` cpp
|
| 12 |
struct process {
|
|
|
|
| 21 |
```
|
| 22 |
|
| 23 |
— *end example*]
|
| 24 |
|
| 25 |
A static member may be referred to directly in the scope of its class or
|
| 26 |
+
in the scope of a class derived [[class.derived]] from its class; in
|
| 27 |
+
this case, the static member is referred to as if a *qualified-id*
|
| 28 |
+
expression was used, with the *nested-name-specifier* of the
|
| 29 |
+
*qualified-id* naming the class scope from which the static member is
|
| 30 |
+
referenced.
|
| 31 |
|
| 32 |
[*Example 2*:
|
| 33 |
|
| 34 |
``` cpp
|
| 35 |
int g();
|
|
|
|
| 42 |
int Y::i = g(); // equivalent to Y::g();
|
| 43 |
```
|
| 44 |
|
| 45 |
— *end example*]
|
| 46 |
|
| 47 |
+
Static members obey the usual class member access rules
|
| 48 |
+
[[class.access]]. When used in the declaration of a class member, the
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
`static` specifier shall only be used in the member declarations that
|
| 50 |
appear within the *member-specification* of the class definition.
|
| 51 |
|
| 52 |
+
[*Note 1*: It cannot be specified in member declarations that appear in
|
| 53 |
namespace scope. — *end note*]
|
| 54 |
|
| 55 |
#### Static member functions <a id="class.static.mfct">[[class.static.mfct]]</a>
|
| 56 |
|
| 57 |
[*Note 1*: The rules described in [[class.mfct]] apply to static
|
| 58 |
member functions. — *end note*]
|
| 59 |
|
| 60 |
+
[*Note 2*: A static member function does not have a `this` pointer
|
| 61 |
+
[[class.this]]. — *end note*]
|
| 62 |
|
| 63 |
A static member function shall not be `virtual`. There shall not be a
|
| 64 |
static and a non-static member function with the same name and the same
|
| 65 |
+
parameter types [[over.load]]. A static member function shall not be
|
| 66 |
declared `const`, `volatile`, or `const volatile`.
|
| 67 |
|
| 68 |
#### Static data members <a id="class.static.data">[[class.static.data]]</a>
|
| 69 |
|
| 70 |
A static data member is not part of the subobjects of a class. If a
|
| 71 |
static data member is declared `thread_local` there is one copy of the
|
| 72 |
member per thread. If a static data member is not declared
|
| 73 |
`thread_local` there is one copy of the data member that is shared by
|
| 74 |
all the objects of the class.
|
| 75 |
|
| 76 |
+
A static data member shall not be `mutable` [[dcl.stc]]. A static data
|
| 77 |
+
member shall not be a direct member [[class.mem]] of an unnamed
|
| 78 |
+
[[class.pre]] or local [[class.local]] class or of a (possibly
|
| 79 |
+
indirectly) nested class [[class.nest]] thereof.
|
| 80 |
+
|
| 81 |
The declaration of a non-inline static data member in its class
|
| 82 |
definition is not a definition and may be of an incomplete type other
|
| 83 |
than cv `void`. The definition for a static data member that is not
|
| 84 |
defined inline in the class definition shall appear in a namespace scope
|
| 85 |
enclosing the member’s class definition. In the definition at namespace
|
| 86 |
scope, the name of the static data member shall be qualified by its
|
| 87 |
class name using the `::` operator. The *initializer* expression in the
|
| 88 |
+
definition of a static data member is in the scope of its class
|
| 89 |
+
[[basic.scope.class]].
|
| 90 |
|
| 91 |
[*Example 1*:
|
| 92 |
|
| 93 |
``` cpp
|
| 94 |
class process {
|
|
|
|
| 124 |
— *end note*]
|
| 125 |
|
| 126 |
If a non-volatile non-inline `const` static data member is of integral
|
| 127 |
or enumeration type, its declaration in the class definition can specify
|
| 128 |
a *brace-or-equal-initializer* in which every *initializer-clause* that
|
| 129 |
+
is an *assignment-expression* is a constant expression [[expr.const]].
|
| 130 |
+
The member shall still be defined in a namespace scope if it is odr-used
|
| 131 |
+
[[basic.def.odr]] in the program and the namespace scope definition
|
| 132 |
+
shall not contain an *initializer*. An inline static data member may be
|
| 133 |
+
defined in the class definition and may specify a
|
| 134 |
*brace-or-equal-initializer*. If the member is declared with the
|
| 135 |
`constexpr` specifier, it may be redeclared in namespace scope with no
|
| 136 |
+
initializer (this usage is deprecated; see [[depr.static.constexpr]]).
|
| 137 |
Declarations of other static data members shall not specify a
|
| 138 |
*brace-or-equal-initializer*.
|
| 139 |
|
| 140 |
+
[*Note 2*: There is exactly one definition of a static data member that
|
| 141 |
+
is odr-used [[basic.def.odr]] in a valid program. — *end note*]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
|
| 143 |
[*Note 3*: Static data members of a class in namespace scope have the
|
| 144 |
+
linkage of the name of the class [[basic.link]]. — *end note*]
|
|
|
|
| 145 |
|
| 146 |
Static data members are initialized and destroyed exactly like non-local
|
| 147 |
variables ([[basic.start.static]], [[basic.start.dynamic]],
|
| 148 |
[[basic.start.term]]).
|
| 149 |
|
|
|
|
|
|