Show: Object Pascal C++
Display Preferences

Pointers To Functions

From Appmethod Topics
Jump to: navigation, search

Go Up to Pointers Index

A pointer to a function is best thought of as an address, usually in a code segment, where that function's executable code is stored; that is, the address to which control is transferred when that function is called.

A pointer to a function has a type called "pointer to function returning type," where type is the function's return type. For example,

void (*func)();

In C++, this is a pointer to a function taking no arguments, and returning void. In C, it's a pointer to a function taking an unspecified number of arguments and returning void. In this example,

void (*func)(int);

*func is a pointer to a function taking an int argument and returning void.

For C++, such a pointer can be used to access static member functions. Pointers to class members must use pointer-to-member operators. See static_cast for details.

Personal tools
In other languages