If you use an overloaded function name
f without
any arguments, that name can refer to a function, a pointer to a function,
a pointer to member function, or a specialization of a function template.
Because you did not provide any arguments, the compiler cannot perform
overload resolution the same way it would for a function call or for
the use of an operator. Instead, the compiler will try to choose the
best viable function that matches the type of one of the following
expressions, depending on where you have used
f:
- An object or reference you are initializing
- The left side of an assignment
- A parameter of a function or a user-defined operator
- The return value of a function, operator, or conversion
- An explicit type conversion
If the compiler chose a declaration of a nonmember function or
a static member function when you used
f, the compiler
matched the declaration with an expression of type pointer-to-function
or reference-to-function. If the compiler chose a declaration of a
nonstatic member function, the compiler matched that declaration with
an expression of type pointer-to-member function. The following example
demonstrates this:
struct X {
int f(int) { return 0; }
static int f(char) { return 0; }
};
int main() {
int (X::*a)(int) = &X::f;
// int (*b)(int) = &X::f;
}
The compiler will not allow the initialization of the
function pointer
b. No nonmember function or static
function of type
int(int) has been declared.