|
1 | 1 | --- |
2 | | -description: "Learn more about: Pointer-to-Member Operators: .* and ->*" |
3 | | -title: "Pointer-to-Member Operators: .* and ->*" |
4 | | -ms.date: "11/04/2016" |
| 2 | +description: "Learn more about: Pointer-to-member operators: '.*' and '->*'" |
| 3 | +title: "Pointer-to-member operators: '.*' and '->*'" |
| 4 | +ms.date: 12/04/2021 |
5 | 5 | f1_keywords: [".*", "->*"] |
6 | 6 | helpviewer_keywords: ["expressions [C++], pointer", "pointer-to-member operators [C++]", ".* operator", "expressions [C++], operators", "->* operator"] |
7 | 7 | ms.assetid: 2632be3f-1c81-4523-b56c-982a92a68688 |
8 | 8 | --- |
9 | | -# Pointer-to-Member Operators: .* and ->* |
| 9 | +# Pointer-to-member operators: `.*` and `->*` |
10 | 10 |
|
11 | 11 | ## Syntax |
12 | 12 |
|
13 | | -``` |
14 | | -expression .* expression |
15 | | -expression ->* expression |
16 | | -``` |
| 13 | +*`pm-expression`*:\ |
| 14 | +  *`cast-expression`*\ |
| 15 | +  *`pm-expression`* **`.*`** *`cast-expression`*\ |
| 16 | +  *`pm-expression`* **`->*`** *`cast-expression`* |
17 | 17 |
|
18 | 18 | ## Remarks |
19 | 19 |
|
20 | | -The pointer-to-member operators, .* and ->\*, return the value of a specific class member for the object specified on the left side of the expression. The right side must specify a member of the class. The following example shows how to use these operators: |
| 20 | +The pointer-to-member operators **`.*`** and **`->*`** return the value of a specific class member for the object specified on the left side of the expression. The right side must specify a member of the class. The following example shows how to use these operators: |
21 | 21 |
|
22 | 22 | ```cpp |
23 | 23 | // expre_Expressions_with_Pointer_Member_Operators.cpp |
@@ -68,13 +68,13 @@ m_func1 |
68 | 68 |
|
69 | 69 | In the preceding example, a pointer to a member, `pmfn`, is used to invoke the member function `m_func1`. Another pointer to a member, `pmd`, is used to access the `m_num` member. |
70 | 70 |
|
71 | | -The binary operator .* combines its first operand, which must be an object of class type, with its second operand, which must be a pointer-to-member type. |
| 71 | +The binary operator **`.*`** combines its first operand, which must be an object of class type, with its second operand, which must be a pointer-to-member type. |
72 | 72 |
|
73 | | -The binary operator ->* combines its first operand, which must be a pointer to an object of class type, with its second operand, which must be a pointer-to-member type. |
| 73 | +The binary operator **`->*`** combines its first operand, which must be a pointer to an object of class type, with its second operand, which must be a pointer-to-member type. |
74 | 74 |
|
75 | | -In an expression containing the .* operator, the first operand must be of the class type of, and be accessible to, the pointer to member specified in the second operand or of an accessible type unambiguously derived from and accessible to that class. |
| 75 | +In an expression containing the **`.*`** operator, the first operand must be of the class type of, and be accessible to, the pointer to member specified in the second operand or of an accessible type unambiguously derived from and accessible to that class. |
76 | 76 |
|
77 | | -In an expression containing the ->* operator, the first operand must be of the type "pointer to the class type" of the type specified in the second operand, or it must be of a type unambiguously derived from that class. |
| 77 | +In an expression containing the **`->*`** operator, the first operand must be of the type "pointer to the class type" of the type specified in the second operand, or it must be of a type unambiguously derived from that class. |
78 | 78 |
|
79 | 79 | ## Example |
80 | 80 |
|
@@ -116,11 +116,11 @@ int main() { |
116 | 116 | } |
117 | 117 | ``` |
118 | 118 |
|
119 | | -The result of the .* or ->\* pointer-to-member operators is an object or function of the type specified in the declaration of the pointer to member. So, in the preceding example, the result of the expression `ADerived.*pmfnFunc1()` is a pointer to a function that returns void. This result is an l-value if the second operand is an l-value. |
| 119 | +The result of the **`.*`** or **`->*`** pointer-to-member operators is an object or function of the type specified in the declaration of the pointer to member. So, in the preceding example, the result of the expression `ADerived.*pmfnFunc1()` is a pointer to a function that returns void. This result is an l-value if the second operand is an l-value. |
120 | 120 |
|
121 | 121 | > [!NOTE] |
122 | 122 | > If the result of one of the pointer-to-member operators is a function, then the result can be used only as an operand to the function call operator. |
123 | 123 |
|
124 | 124 | ## See also |
125 | 125 |
|
126 | | -[C++ Built-in Operators, Precedence and Associativity](../cpp/cpp-built-in-operators-precedence-and-associativity.md) |
| 126 | +[C++ built-in operators, precedence, and associativity](../cpp/cpp-built-in-operators-precedence-and-associativity.md) |
0 commit comments