tmp/tmp7fbo1z9g/{from.md → to.md}
RENAMED
|
@@ -8,31 +8,35 @@ pm-expression:
|
|
| 8 |
pm-expression '.*' cast-expression
|
| 9 |
pm-expression '->*' cast-expression
|
| 10 |
```
|
| 11 |
|
| 12 |
The binary operator `.*` binds its second operand, which shall be of
|
| 13 |
-
type “pointer to member of `T`” to its first operand, which shall be
|
| 14 |
-
class `T` or of a class of which `T` is an unambiguous and
|
| 15 |
-
base class. The result is an object or a function of the type
|
| 16 |
-
by the second operand.
|
| 17 |
|
| 18 |
The binary operator `->*` binds its second operand, which shall be of
|
| 19 |
type “pointer to member of `T`” to its first operand, which shall be of
|
| 20 |
-
type “pointer to `
|
| 21 |
-
unambiguous and accessible base class.
|
| 22 |
converted into the equivalent form `(*(E1)).*E2`.
|
| 23 |
|
| 24 |
Abbreviating *pm-expression*`.*`*cast-expression* as `E1.*E2`, `E1` is
|
| 25 |
called the *object expression*. If the dynamic type of `E1` does not
|
| 26 |
contain the member to which `E2` refers, the behavior is undefined.
|
|
|
|
| 27 |
|
| 28 |
The restrictions on *cv-*qualification, and the manner in which the
|
| 29 |
*cv-*qualifiers of the operands are combined to produce the
|
| 30 |
*cv-*qualifiers of the result, are the same as the rules for `E1.E2`
|
| 31 |
-
given in [[expr.ref]].
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
``` cpp
|
| 36 |
struct S {
|
| 37 |
S() : i(0) { }
|
| 38 |
mutable int i;
|
|
@@ -43,25 +47,32 @@ const S cs;
|
|
| 43 |
int S::* pm = &S::i; // pm refers to mutable member S::i
|
| 44 |
cs.*pm = 88; // ill-formed: cs is a const object
|
| 45 |
}
|
| 46 |
```
|
| 47 |
|
|
|
|
|
|
|
| 48 |
If the result of `.*` or `->*` is a function, then that result can be
|
| 49 |
used only as the operand for the function call operator `()`.
|
| 50 |
|
|
|
|
|
|
|
| 51 |
``` cpp
|
| 52 |
(ptr_to_obj->*ptr_to_mfct)(10);
|
| 53 |
```
|
| 54 |
|
| 55 |
calls the member function denoted by `ptr_to_mfct` for the object
|
| 56 |
-
pointed to by `ptr_to_obj`.
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
the
|
|
|
|
|
|
|
|
|
|
| 67 |
|
|
|
|
| 8 |
pm-expression '.*' cast-expression
|
| 9 |
pm-expression '->*' cast-expression
|
| 10 |
```
|
| 11 |
|
| 12 |
The binary operator `.*` binds its second operand, which shall be of
|
| 13 |
+
type “pointer to member of `T`” to its first operand, which shall be a
|
| 14 |
+
glvalue of class `T` or of a class of which `T` is an unambiguous and
|
| 15 |
+
accessible base class. The result is an object or a function of the type
|
| 16 |
+
specified by the second operand.
|
| 17 |
|
| 18 |
The binary operator `->*` binds its second operand, which shall be of
|
| 19 |
type “pointer to member of `T`” to its first operand, which shall be of
|
| 20 |
+
type “pointer to `U`” where `U` is either `T` or a class of which `T` is
|
| 21 |
+
an unambiguous and accessible base class. The expression `E1->*E2` is
|
| 22 |
converted into the equivalent form `(*(E1)).*E2`.
|
| 23 |
|
| 24 |
Abbreviating *pm-expression*`.*`*cast-expression* as `E1.*E2`, `E1` is
|
| 25 |
called the *object expression*. If the dynamic type of `E1` does not
|
| 26 |
contain the member to which `E2` refers, the behavior is undefined.
|
| 27 |
+
Otherwise, the expression `E1` is sequenced before the expression `E2`.
|
| 28 |
|
| 29 |
The restrictions on *cv-*qualification, and the manner in which the
|
| 30 |
*cv-*qualifiers of the operands are combined to produce the
|
| 31 |
*cv-*qualifiers of the result, are the same as the rules for `E1.E2`
|
| 32 |
+
given in [[expr.ref]].
|
| 33 |
+
|
| 34 |
+
[*Note 1*:
|
| 35 |
+
|
| 36 |
+
It is not possible to use a pointer to member that refers to a `mutable`
|
| 37 |
+
member to modify a `const` class object. For example,
|
| 38 |
|
| 39 |
``` cpp
|
| 40 |
struct S {
|
| 41 |
S() : i(0) { }
|
| 42 |
mutable int i;
|
|
|
|
| 47 |
int S::* pm = &S::i; // pm refers to mutable member S::i
|
| 48 |
cs.*pm = 88; // ill-formed: cs is a const object
|
| 49 |
}
|
| 50 |
```
|
| 51 |
|
| 52 |
+
— *end note*]
|
| 53 |
+
|
| 54 |
If the result of `.*` or `->*` is a function, then that result can be
|
| 55 |
used only as the operand for the function call operator `()`.
|
| 56 |
|
| 57 |
+
[*Example 1*:
|
| 58 |
+
|
| 59 |
``` cpp
|
| 60 |
(ptr_to_obj->*ptr_to_mfct)(10);
|
| 61 |
```
|
| 62 |
|
| 63 |
calls the member function denoted by `ptr_to_mfct` for the object
|
| 64 |
+
pointed to by `ptr_to_obj`.
|
| 65 |
+
|
| 66 |
+
— *end example*]
|
| 67 |
+
|
| 68 |
+
In a `.*` expression whose object expression is an rvalue, the program
|
| 69 |
+
is ill-formed if the second operand is a pointer to member function with
|
| 70 |
+
*ref-qualifier* `&`. In a `.*` expression whose object expression is an
|
| 71 |
+
lvalue, the program is ill-formed if the second operand is a pointer to
|
| 72 |
+
member function with *ref-qualifier* `&&`. The result of a `.*`
|
| 73 |
+
expression whose second operand is a pointer to a data member is an
|
| 74 |
+
lvalue if the first operand is an lvalue and an xvalue otherwise. The
|
| 75 |
+
result of a `.*` expression whose second operand is a pointer to a
|
| 76 |
+
member function is a prvalue. If the second operand is the null member
|
| 77 |
+
pointer value ([[conv.mem]]), the behavior is undefined.
|
| 78 |
|