tmp/tmpf3a14yoo/{from.md → to.md}
RENAMED
|
@@ -1,21 +1,24 @@
|
|
| 1 |
-
### Static data members <a id="class.static.data">[[class.static.data]]</a>
|
| 2 |
|
| 3 |
-
A
|
| 4 |
-
|
| 5 |
-
member per thread. If a
|
| 6 |
`thread_local` there is one copy of the data member that is shared by
|
| 7 |
all the objects of the class.
|
| 8 |
|
| 9 |
-
The declaration of a
|
| 10 |
-
a definition and may be of an incomplete type other
|
| 11 |
-
`void`. The definition for a
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
in the scope of its class (
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
``` cpp
|
| 19 |
class process {
|
| 20 |
static process* run_chain;
|
| 21 |
static process* running;
|
|
@@ -23,44 +26,59 @@ class process {
|
|
| 23 |
|
| 24 |
process* process::running = get_main();
|
| 25 |
process* process::run_chain = running;
|
| 26 |
```
|
| 27 |
|
| 28 |
-
The
|
| 29 |
global scope; the notation `process::run_chain` specifies that the
|
| 30 |
member `run_chain` is a member of class `process` and in the scope of
|
| 31 |
-
class `process`. In the
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
*
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
Unnamed classes and classes contained directly or indirectly within
|
| 56 |
-
unnamed classes shall not contain
|
| 57 |
|
| 58 |
-
|
| 59 |
-
linkage ([[basic.link]]). A local class
|
| 60 |
-
members.
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
|
|
|
| 64 |
|
| 65 |
-
A
|
| 66 |
|
|
|
|
| 1 |
+
#### Static data members <a id="class.static.data">[[class.static.data]]</a>
|
| 2 |
|
| 3 |
+
A static data member is not part of the subobjects of a class. If a
|
| 4 |
+
static data member is declared `thread_local` there is one copy of the
|
| 5 |
+
member per thread. If a static data member is not declared
|
| 6 |
`thread_local` there is one copy of the data member that is shared by
|
| 7 |
all the objects of the class.
|
| 8 |
|
| 9 |
+
The declaration of a non-inline static data member in its class
|
| 10 |
+
definition is not a definition and may be of an incomplete type other
|
| 11 |
+
than cv `void`. The definition for a static data member that is not
|
| 12 |
+
defined inline in the class definition shall appear in a namespace scope
|
| 13 |
+
enclosing the member’s class definition. In the definition at namespace
|
| 14 |
+
scope, the name of the static data member shall be qualified by its
|
| 15 |
+
class name using the `::` operator. The *initializer* expression in the
|
| 16 |
+
definition of a static data member is in the scope of its class (
|
| 17 |
+
[[basic.scope.class]]).
|
| 18 |
+
|
| 19 |
+
[*Example 1*:
|
| 20 |
|
| 21 |
``` cpp
|
| 22 |
class process {
|
| 23 |
static process* run_chain;
|
| 24 |
static process* running;
|
|
|
|
| 26 |
|
| 27 |
process* process::running = get_main();
|
| 28 |
process* process::run_chain = running;
|
| 29 |
```
|
| 30 |
|
| 31 |
+
The static data member `run_chain` of class `process` is defined in
|
| 32 |
global scope; the notation `process::run_chain` specifies that the
|
| 33 |
member `run_chain` is a member of class `process` and in the scope of
|
| 34 |
+
class `process`. In the static data member definition, the *initializer*
|
| 35 |
+
expression refers to the static data member `running` of class
|
| 36 |
+
`process`.
|
| 37 |
+
|
| 38 |
+
— *end example*]
|
| 39 |
+
|
| 40 |
+
[*Note 1*:
|
| 41 |
+
|
| 42 |
+
Once the static data member has been defined, it exists even if no
|
| 43 |
+
objects of its class have been created.
|
| 44 |
+
|
| 45 |
+
[*Example 2*:
|
| 46 |
+
|
| 47 |
+
In the example above, `run_chain` and `running` exist even if no objects
|
| 48 |
+
of class `process` are created by the program.
|
| 49 |
+
|
| 50 |
+
— *end example*]
|
| 51 |
+
|
| 52 |
+
— *end note*]
|
| 53 |
+
|
| 54 |
+
If a non-volatile non-inline `const` static data member is of integral
|
| 55 |
+
or enumeration type, its declaration in the class definition can specify
|
| 56 |
+
a *brace-or-equal-initializer* in which every *initializer-clause* that
|
| 57 |
+
is an *assignment-expression* is a constant expression (
|
| 58 |
+
[[expr.const]]). The member shall still be defined in a namespace scope
|
| 59 |
+
if it is odr-used ([[basic.def.odr]]) in the program and the namespace
|
| 60 |
+
scope definition shall not contain an *initializer*. An inline static
|
| 61 |
+
data member may be defined in the class definition and may specify a
|
| 62 |
+
*brace-or-equal-initializer*. If the member is declared with the
|
| 63 |
+
`constexpr` specifier, it may be redeclared in namespace scope with no
|
| 64 |
+
initializer (this usage is deprecated; see [[depr.static_constexpr]]).
|
| 65 |
+
Declarations of other static data members shall not specify a
|
| 66 |
+
*brace-or-equal-initializer*.
|
| 67 |
+
|
| 68 |
+
[*Note 2*: There shall be exactly one definition of a static data
|
| 69 |
+
member that is odr-used ([[basic.def.odr]]) in a program; no diagnostic
|
| 70 |
+
is required. — *end note*]
|
| 71 |
+
|
| 72 |
Unnamed classes and classes contained directly or indirectly within
|
| 73 |
+
unnamed classes shall not contain static data members.
|
| 74 |
|
| 75 |
+
[*Note 3*: Static data members of a class in namespace scope have the
|
| 76 |
+
linkage of that class ([[basic.link]]). A local class cannot have
|
| 77 |
+
static data members ([[class.local]]). — *end note*]
|
| 78 |
|
| 79 |
+
Static data members are initialized and destroyed exactly like non-local
|
| 80 |
+
variables ([[basic.start.static]], [[basic.start.dynamic]],
|
| 81 |
+
[[basic.start.term]]).
|
| 82 |
|
| 83 |
+
A static data member shall not be `mutable` ([[dcl.stc]]).
|
| 84 |
|