Function Pointer Parameters

Just as with arrays (§ 6.2.4, p. 214), we cannot define parameters of function type but can have a parameter that is a pointer to function. As with arrays, we can write a parameter that looks like a function type, but it will be treated as a pointer:

// third parameter is a function type and is automatically treated as a pointer to functionvoid useBigger(const string &s1, const string &s2,               bool pf(const string &, const string &));// equivalent declaration: explicitly define the parameter as a pointer to functionvoid useBigger(const string &s1, const string &s2,               bool (*pf)(const string &, const string &));

When we pass a function as an argument, we can do so directly. It will be automatically ...

Get C++ Primer, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.