tmp/tmpe39uquod/{from.md → to.md}
RENAMED
|
@@ -1,63 +0,0 @@
|
|
| 1 |
-
#### The `this` pointer <a id="class.this">[[class.this]]</a>
|
| 2 |
-
|
| 3 |
-
In the body of a non-static [[class.mfct]] member function, the keyword
|
| 4 |
-
`this` is a prvalue whose value is a pointer to the object for which the
|
| 5 |
-
function is called. The type of `this` in a member function whose type
|
| 6 |
-
has a *cv-qualifier-seq* cv and whose class is `X` is “pointer to cv
|
| 7 |
-
`X`”.
|
| 8 |
-
|
| 9 |
-
[*Note 1*: Thus in a const member function, the object for which the
|
| 10 |
-
function is called is accessed through a const access
|
| 11 |
-
path. — *end note*]
|
| 12 |
-
|
| 13 |
-
[*Example 1*:
|
| 14 |
-
|
| 15 |
-
``` cpp
|
| 16 |
-
struct s {
|
| 17 |
-
int a;
|
| 18 |
-
int f() const;
|
| 19 |
-
int g() { return a++; }
|
| 20 |
-
int h() const { return a++; } // error
|
| 21 |
-
};
|
| 22 |
-
|
| 23 |
-
int s::f() const { return a; }
|
| 24 |
-
```
|
| 25 |
-
|
| 26 |
-
The `a++` in the body of `s::h` is ill-formed because it tries to modify
|
| 27 |
-
(a part of) the object for which `s::h()` is called. This is not allowed
|
| 28 |
-
in a const member function because `this` is a pointer to `const`; that
|
| 29 |
-
is, `*this` has `const` type.
|
| 30 |
-
|
| 31 |
-
— *end example*]
|
| 32 |
-
|
| 33 |
-
[*Note 2*: Similarly, `volatile` semantics [[dcl.type.cv]] apply in
|
| 34 |
-
volatile member functions when accessing the object and its non-static
|
| 35 |
-
data members. — *end note*]
|
| 36 |
-
|
| 37 |
-
A member function whose type has a *cv-qualifier-seq* *cv1* can be
|
| 38 |
-
called on an object expression [[expr.ref]] of type *cv2* `T` only if
|
| 39 |
-
*cv1* is the same as or more cv-qualified than *cv2*
|
| 40 |
-
[[basic.type.qualifier]].
|
| 41 |
-
|
| 42 |
-
[*Example 2*:
|
| 43 |
-
|
| 44 |
-
``` cpp
|
| 45 |
-
void k(s& x, const s& y) {
|
| 46 |
-
x.f();
|
| 47 |
-
x.g();
|
| 48 |
-
y.f();
|
| 49 |
-
y.g(); // error
|
| 50 |
-
}
|
| 51 |
-
```
|
| 52 |
-
|
| 53 |
-
The call `y.g()` is ill-formed because `y` is `const` and `s::g()` is a
|
| 54 |
-
non-const member function, that is, `s::g()` is less-qualified than the
|
| 55 |
-
object expression `y`.
|
| 56 |
-
|
| 57 |
-
— *end example*]
|
| 58 |
-
|
| 59 |
-
[*Note 3*: Constructors and destructors cannot be declared `const`,
|
| 60 |
-
`volatile`, or `const` `volatile`. However, these functions can be
|
| 61 |
-
invoked to create and destroy objects with cv-qualified types; see
|
| 62 |
-
[[class.ctor]] and [[class.dtor]]. — *end note*]
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|