From Jason Turner

[class.this]

Diff to HTML by rtfpessoa

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