In the parameter’s of a function, I want to pass a default argument that is a function template. What I’m trying to decipher is the difference between (*cmp) or (cmp) in the function below:
template <typename Type>
int Foo(some var, int (*cmp)(Type one, Type two) = FunctTemplate) { ...
I am used to seeing the * as a pointer declaration… Is this a pointer to the function FunctTemplate? Why does the program see to work regardless of way I write it (astrik or no astrik)?
The types are not the same, but there is no difference when they are used as a parameter type in a function declaration.
In
int (*cmp)(Type, Type),cmphas pointer-to-function type (or a “function pointer” type).In
int (cmp)(Type, Type),cmphas function type (i.e., it is not a pointer type at all).However, C and C++ both have a rule that any parameter that has a function type is implicitly converted to the corresponding function pointer type, just as any parameter that has an array type is implicitly converted to the corresponding pointer type.