[over.over] (original) (raw)

12 Overloading [over]

12.5 Address of overloaded function [over.over]

A use of a function name without arguments is resolved to a function, a pointer to function, or a pointer to member function for a specific function that is chosen from a set of selected functions determined based on the target type required in the context (if any), as described below.

The target can be

The function name can be preceded by the & operator.

[Note 1:

Any redundant set of parentheses surrounding the function name is ignored ([expr.prim.paren]).

— _end note_]

If there is no target, all non-template functions named are selected.

Otherwise, a non-template function with type Fis selected for the function type FT of the target type if F(after possibly applying the function pointer conversion ([conv.fctptr])) is identical to FT.

[Note 2:

That is, the class of which the function is a member is ignored when matching a pointer-to-member-function type.

— _end note_]

For each function template designated by the name, template argument deduction is done ([temp.deduct.funcaddr]), and if the argument deduction succeeds, the resulting template argument list is used to generate a single function template specialization, which is added to the set of selected functions considered.

[Note 3:

As described in [temp.arg.explicit], if deduction fails and the function template name is followed by an explicit template argument list, thetemplate-idis then examined to see whether it identifies a single function template specialization.

If it does, thetemplate-idis considered to be an lvalue for that function template specialization.

The target type is not used in that determination.

— _end note_]

Non-member functions and static member functions match targets of function pointer type or reference to function type.

Non-static member functions match targets of pointer-to-member-function type.

If a non-static member function is selected, the reference to the overloaded function name is required to have the form of a pointer to member as described in [expr.unary.op].

All functions with associated constraints that are not satisfied ([temp.constr.decl]) are eliminated from the set of selected functions.

If more than one function in the set remains, all function template specializations in the set are eliminated if the set also contains a function that is not a function template specialization.

Any given non-template functionF0is eliminated if the set contains a second non-template function that is more constrained thanF0according to the partial ordering rules of [temp.constr.order].

Any given function template specializationF1is eliminated if the set contains a second function template specialization whose function template is more specialized than the function template ofF1according to the partial ordering rules of [temp.func.order].

After such eliminations, if any, there shall remain exactly one selected function.

[Example 1: int f(double);int f(int);int (*pfd)(double) = &f; int (*pfi)(int) = &f; int (*pfe)(...) = &f; int (&rfi)(int) = f; int (&rfd)(double) = f; void g() { (int (*)(int))&f; }

The initialization ofpfeis ill-formed because nof()with typeint(...)has been declared, and not because of any ambiguity.

For another example,

struct X { int f(int);static int f(long);};int (X::*p1)(int) = &X::f; int (*p2)(int) = &X::f; int (*p3)(long) = &X::f; int (X::*p4)(long) = &X::f; int (X::*p5)(int) = &(X::f); int (*p6)(long) = &(X::f); — _end example_]

[Note 4:

Iff()andg()are both overloaded functions, the Cartesian product of possibilities is considered to resolvef(&g), or the equivalent expressionf(g).

— _end note_]

[Note 5:

Even if B is a public base of D, we haveD* f(); B* (*p1)() = &f; void g(D*);void (*p2)(B*) = &g;

— _end note_]