6.7. Pointers to Functions
A function pointer is just that—a pointer that denotes a function rather than an object. Like any other pointer, a function pointer points to a particular type. A function’s type is determined by its return type and the types of its parameters. The function’s name is not part of its type. For example:
// compares lengths of two stringsbool lengthCompare(const string &, const string &);
has type bool(const string&, const string&). To declare a pointer that can point at this function, we declare a pointer in place of the function name:
// pf points to a function returning bool that takes two const string referencesbool (*pf)(const string &, const string &); // uninitialized
Starting from the name we are declaring, we ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access