Skip to content

Commit 45932d9

Browse files
authored
Merge pull request #2634 from corob-msft/cr-ko-kr-964
Add no-loc to this pointer article.
2 parents d253ffc + b920405 commit 45932d9

1 file changed

Lines changed: 25 additions & 21 deletions

File tree

docs/cpp/this-pointer.md

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
---
2-
title: "this Pointer"
3-
ms.date: "11/04/2016"
2+
title: "this pointer"
3+
description: "The this pointer is a compiler-generated pointer to the current object in nonstatic member functions."
4+
ms.date: "01/22/2020"
45
f1_keywords: ["this_cpp"]
56
helpviewer_keywords: ["nonstatic member functions [C++]", "pointers, to class instance", "this pointer"]
67
ms.assetid: 92e3256a-4ad9-4d46-8be1-d77fad90791f
8+
no-loc: [this, class, struct, union, sizeof, const, volatile]
79
---
8-
# this Pointer
10+
# this pointer
911

10-
The **this** pointer is a pointer accessible only within the nonstatic member functions of a **class**, **struct**, or **union** type. It points to the object for which the member function is called. Static member functions do not have a **this** pointer.
12+
The **this** pointer is a pointer accessible only within the nonstatic member functions of a **class**, **struct**, or **union** type. It points to the object for which the member function is called. Static member functions don't have a **this** pointer.
1113

1214
## Syntax
1315

@@ -18,19 +20,19 @@ this->member-identifier
1820

1921
## Remarks
2022

21-
An object's **this** pointer is not part of the object itself; it is not reflected in the result of a **sizeof** statement on the object. Instead, when a nonstatic member function is called for an object, the address of the object is passed by the compiler as a hidden argument to the function. For example, the following function call:
23+
An object's **this** pointer isn't part of the object itself. It's not reflected in the result of a **sizeof** statement on the object. When a nonstatic member function is called for an object, the compiler passes the object's address to the function as a hidden argument. For example, the following function call:
2224

2325
```cpp
2426
myDate.setMonth( 3 );
2527
```
2628

27-
can be interpreted this way:
29+
can be interpreted as:
2830

2931
```cpp
3032
setMonth( &myDate, 3 );
3133
```
3234
33-
The object's address is available from within the member function as the **this** pointer. Most uses of **this** are implicit. It is legal, though unnecessary, to explicitly use **this** when referring to members of the class. For example:
35+
The object's address is available from within the member function as the **this** pointer. Most **this** pointer uses are implicit. It's legal, though unnecessary, to use an explicit **this** when referring to members of the class. For example:
3436
3537
```cpp
3638
void Date::setMonth( int mn )
@@ -55,7 +57,7 @@ if (&Object != this) {
5557
```
5658
5759
> [!NOTE]
58-
> Because the **this** pointer is nonmodifiable, assignments to **this** are not allowed. Earlier implementations of C++ allowed assignments to **this**.
60+
> Because the **this** pointer is nonmodifiable, assignments to the **this** pointer are not allowed. Earlier implementations of C++ allowed assignment to **this**.
5961
6062
Occasionally, the **this** pointer is used directly — for example, to manipulate self-referential data structures, where the address of the current object is required.
6163
@@ -131,9 +133,9 @@ your buffer
131133

132134
## Type of the this pointer
133135

134-
The **this** pointer's type can be modified in the function declaration by the **const** and **volatile** keywords. To declare a function as having the attributes of one or more of these keywords, add the keyword(s) after the function argument list.
136+
The **this** pointer's type can be modified in the function declaration by the **const** and **volatile** keywords. To declare a function that has either of these attributes, add the keyword(s) after the function argument list.
135137

136-
Consider this example:
138+
Consider an example:
137139

138140
```cpp
139141
// type_of_this_pointer1.cpp
@@ -146,7 +148,7 @@ int main()
146148
}
147149
```
148150

149-
The preceding code declares a member function, `X`, in which the **this** pointer is treated as a **const** pointer to a **const** object. Combinations of *cv-mod-list* options can be used, but they always modify the object pointed to by **this**, not the **this** pointer itself. Therefore, the following declaration declares function `X`; the **this** pointer is a **const** pointer to a **const** object:
151+
The preceding code declares a member function, `X`, in which the **this** pointer is treated as a **const** pointer to a **const** object. Combinations of *cv-mod-list* options can be used, but they always modify the object pointed to by the **this** pointer, not the pointer itself. The following declaration declares function `X`, where the **this** pointer is a **const** pointer to a **const** object:
150152

151153
```cpp
152154
// type_of_this_pointer2.cpp
@@ -159,28 +161,30 @@ int main()
159161
}
160162
```
161163

162-
The type of **this** in a member function is described by the following syntax, where *cv-qualifier-list* is determined from the member functions declarator and can be **const** or **volatile** (or both), and *class-type* is the name of the class:
164+
The type of **this** in a member function is described by the following syntax. The *cv-qualifier-list* is determined from the member function's declarator. It can be **const** or **volatile** (or both). *class-type* is the name of the class:
163165

164-
*[cv-qualifier-list] class-type* *** const this**
166+
[*cv-qualifier-list*] *class-type* **\* const this**
165167

166-
In other words, **this** is always a const pointer; it cannot be reassigned. The **const** or **volatile** qualifiers used in the member function declaration apply to the class instance pointed to by **this** in the scope of that function.
168+
In other words, the **this** pointer is always a const pointer. It can't be reassigned. The **const** or **volatile** qualifiers used in the member function declaration apply to the class instance the **this** pointer points at, in the scope of that function.
167169

168170
The following table explains more about how these modifiers work.
169171

170-
### Semantics of this Modifiers
172+
### Semantics of this modifiers
171173

172174
|Modifier|Meaning|
173175
|--------------|-------------|
174-
|**const**|Cannot change member data; cannot invoke member functions that are not **const**.|
175-
|**volatile**|Member data is loaded from memory each time it is accessed; disables certain optimizations.|
176+
|**const**|Can't change member data; can't invoke member functions that aren't **const**.|
177+
|**volatile**|Member data is loaded from memory each time it's accessed; disables certain optimizations.|
176178

177-
It is an error to pass a **const** object to a member function that is not **const**. Similarly, it is an error to pass a **volatile** object to a member function that is not **volatile**.
179+
It's an error to pass a **const** object to a member function that isn't **const**.
178180

179-
Member functions declared as **const** cannot change member data — in such functions, the **this** pointer is a pointer to a **const** object.
181+
Similarly, it's also an error to pass a **volatile** object to a member function that isn't **volatile**.
182+
183+
Member functions declared as **const** can't change member data — in such functions, the **this** pointer is a pointer to a **const** object.
180184

181185
> [!NOTE]
182-
> Constructors and destructors cannot be declared as **const** or **volatile**. They can, however, be invoked on **const** or **volatile** objects.
186+
> Constructors and destructors can't be declared as **const** or **volatile**. They can, however, be invoked on **const** or **volatile** objects.
183187
184188
## See also
185189

186-
[Keywords](../cpp/keywords-cpp.md)
190+
[Keywords](../cpp/keywords-cpp.md)

0 commit comments

Comments
 (0)