|
154 | 154 | \indextext{function!overload resolution and}%
|
155 | 155 | The set of candidate functions can contain both member and non-member
|
156 | 156 | functions to be resolved against the same argument list.
|
157 |
| -So that argument and parameter lists are comparable within this |
158 |
| -heterogeneous set, a member function that does not have an explicit object parameter is considered to have an |
159 |
| -extra first parameter, called the |
160 |
| -\defn{implicit object parameter}, |
161 |
| -which represents the object for which the member function has been |
162 |
| -called. |
163 |
| -For the purposes of overload resolution, both static and |
164 |
| -non-static member functions have an object parameter, |
165 |
| -but constructors do not. |
| 157 | +If a member function is |
| 158 | +\begin{itemize} |
| 159 | +\item |
| 160 | +an implicit object member function that is not a constructor, or |
| 161 | +\item |
| 162 | +a static member function and |
| 163 | +the argument list includes an implied object argument, |
| 164 | +\end{itemize} |
| 165 | +it is considered to have an extra first parameter, |
| 166 | +called the \defnadj{implicit}{object parameter}, |
| 167 | +which represents the object for which the member function has been called. |
166 | 168 |
|
167 | 169 | \pnum
|
168 | 170 | Similarly, when appropriate, the context can construct an
|
|
367 | 369 | \pnum
|
368 | 370 | If the \grammarterm{postfix-expression} is the address of an overload set,
|
369 | 371 | overload resolution is applied using that set as described above.
|
370 |
| -If the function selected by overload resolution is a non-static member function, |
| 372 | +\begin{note} |
| 373 | +No implied object argument is added in this case. |
| 374 | +\end{note} |
| 375 | +If the function selected by overload resolution is |
| 376 | +an implicit object member function, |
371 | 377 | the program is ill-formed.
|
372 | 378 | \begin{note}
|
373 | 379 | The resolution of the address of an
|
|
443 | 449 | The function declarations found by name lookup\iref{basic.lookup} constitute the
|
444 | 450 | set of candidate functions.
|
445 | 451 | Because of the rules for name lookup, the set of candidate functions
|
446 |
| -consists (1) entirely of non-member functions or (2) entirely of |
| 452 | +consists either entirely of non-member functions or entirely of |
447 | 453 | member functions of some class
|
448 | 454 | \tcode{T}.
|
449 |
| -In case (1), |
| 455 | +In the former case or |
| 456 | +if the \grammarterm{primary-expression} is the address of an overload set, |
450 | 457 | the argument list is
|
451 | 458 | the same as the
|
452 | 459 | \grammarterm{expression-list}
|
453 | 460 | in the call.
|
454 |
| -In case (2), the argument list is the |
| 461 | +Otherwise, the argument list is the |
455 | 462 | \grammarterm{expression-list}
|
456 | 463 | in the call augmented by the addition of an implied object
|
457 | 464 | argument as in a qualified function call.
|
|
485 | 492 | a(); // OK, \tcode{(*this).a()}
|
486 | 493 | }
|
487 | 494 |
|
| 495 | +void c(this const C&); // \#1 |
| 496 | +void c()&; // \#2 |
| 497 | +static void c(int = 0); // \#3 |
| 498 | + |
| 499 | +void d() { |
| 500 | + c(); // error: ambiguous between \#2 and \#3 |
| 501 | + (C::c)(); // error: as above |
| 502 | + (&(C::c))(); // error: cannot resolve address of overloaded \tcode{this->C::c}\iref{over.over} |
| 503 | + (&C::c)(C{}); // selects \#1 |
| 504 | + (&C::c)(*this); // error: selects \#2, and is ill-formed\iref{over.match.call.general} |
| 505 | + (&C::c)(); // selects \#3 |
| 506 | +} |
| 507 | + |
488 | 508 | void f(this const C&);
|
489 | 509 | void g() const {
|
490 | 510 | f(); // OK, \tcode{(*this).f()}
|
|
0 commit comments