tmp/tmppl0qguij/{from.md → to.md}
RENAMED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### This <a id="expr.prim.this">[[expr.prim.this]]</a>
|
| 2 |
+
|
| 3 |
+
The keyword `this` names a pointer to the object for which a non-static
|
| 4 |
+
member function ([[class.this]]) is invoked or a non-static data
|
| 5 |
+
member’s initializer ([[class.mem]]) is evaluated.
|
| 6 |
+
|
| 7 |
+
If a declaration declares a member function or member function template
|
| 8 |
+
of a class `X`, the expression `this` is a prvalue of type “pointer to
|
| 9 |
+
*cv-qualifier-seq* `X`” between the optional *cv-qualifier-seq* and the
|
| 10 |
+
end of the *function-definition*, *member-declarator*, or *declarator*.
|
| 11 |
+
It shall not appear before the optional *cv-qualifier-seq* and it shall
|
| 12 |
+
not appear within the declaration of a static member function (although
|
| 13 |
+
its type and value category are defined within a static member function
|
| 14 |
+
as they are within a non-static member function).
|
| 15 |
+
|
| 16 |
+
[*Note 1*: This is because declaration matching does not occur until
|
| 17 |
+
the complete declarator is known. — *end note*]
|
| 18 |
+
|
| 19 |
+
Unlike the object expression in other contexts, `*this` is not required
|
| 20 |
+
to be of complete type for purposes of class member access (
|
| 21 |
+
[[expr.ref]]) outside the member function body.
|
| 22 |
+
|
| 23 |
+
[*Note 2*: Only class members declared prior to the declaration are
|
| 24 |
+
visible. — *end note*]
|
| 25 |
+
|
| 26 |
+
[*Example 1*:
|
| 27 |
+
|
| 28 |
+
``` cpp
|
| 29 |
+
struct A {
|
| 30 |
+
char g();
|
| 31 |
+
template<class T> auto f(T t) -> decltype(t + g())
|
| 32 |
+
{ return t + g(); }
|
| 33 |
+
};
|
| 34 |
+
template auto A::f(int t) -> decltype(t + g());
|
| 35 |
+
```
|
| 36 |
+
|
| 37 |
+
— *end example*]
|
| 38 |
+
|
| 39 |
+
Otherwise, if a *member-declarator* declares a non-static data member (
|
| 40 |
+
[[class.mem]]) of a class `X`, the expression `this` is a prvalue of
|
| 41 |
+
type “pointer to `X`” within the optional default member initializer (
|
| 42 |
+
[[class.mem]]). It shall not appear elsewhere in the
|
| 43 |
+
*member-declarator*.
|
| 44 |
+
|
| 45 |
+
The expression `this` shall not appear in any other context.
|
| 46 |
+
|
| 47 |
+
[*Example 2*:
|
| 48 |
+
|
| 49 |
+
``` cpp
|
| 50 |
+
class Outer {
|
| 51 |
+
int a[sizeof(*this)]; // error: not inside a member function
|
| 52 |
+
unsigned int sz = sizeof(*this); // OK: in default member initializer
|
| 53 |
+
|
| 54 |
+
void f() {
|
| 55 |
+
int b[sizeof(*this)]; // OK
|
| 56 |
+
|
| 57 |
+
struct Inner {
|
| 58 |
+
int c[sizeof(*this)]; // error: not inside a member function of Inner
|
| 59 |
+
};
|
| 60 |
+
}
|
| 61 |
+
};
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
— *end example*]
|
| 65 |
+
|