T (* fp)(arg list)
- bool (* comp)(int, int)
bool (* comp)(int, int);
is not the same as
bool * comp(int, int);
extern
declaration for a function returning a pointer to a
boolean)
()
- it's an operator(!)
::
is highest) - watch those
parenthesis
(* comp)(1, 2)
is not the same as * comp(1, 2)
.
()
can be overloaded(!) - used
heavily in the stl (function objects or functors).
&
- not really necessary; a function name is a function
pointer - similar to array names
bool (*comp)(int, int) = &less;
is the same as
bool (*comp)(int, int) = less;
*
- not really necessary for calls; compilers
automatically follow function pointers when necessary
(* comp)(3, 4)
is the same as comp(3, 4)
.
*
must appear
double find_min(double, double, double (* fp)(double)
_if
ones, in particular)
widget::widget(void (* efp)(args), args)
struct device_driver { int (* open)(const char * name, mode_t mode); int (* close)(void); int (* read)(char * data, unsigned size); int (* write)(const char * data, unsigned size); } device_driver disk_device_driver = { disk_open, disk_close, disk_read, disk_write }; device_driver tty_device_driver = { tty_open, tty_close, tty_read, tty_write }; void t(void) { device_driver dd = disk_device_driver; (dd.open)("/dev/null", R_ONLY); }
typedef int (* next_state)(input);
next_state fsm[] = { r1, r2, ... };
current_state = fsm[current_state](input);
.*
and ->*
syntax (neither overloadable)
operator ()
is much more fun, though
This page last modified on 20 November 2001.