A function object, also called a functor, functional, or functionoid, is a computer programming construct allowing an object to be invoked or called as if it were an ordinary function, usually with the same syntax.
/* Callback function */ int compare_function(int A, int B) {
return A < B;
} … /* Declaration of C sorting function */ void sort_ints(int* begin_items, int num_items, int (*cmpfunc)(int, int) ); … int main(void) {
int items[] = {4, 3, 1, 2}; sort_ints(items, sizeof(items)/sizeof(int), compare_function); return 0;
}
C++ could use Fuction instead Callback:
class that will act as a function class compare_class { public: bool operator()(int A, int B) { return (A < B); } }; … Declaration of C++ sorting function. template <class ComparisonFunctor>
void sort_ints(int* begin_items, int num_items, ComparisonFunctor c); … int main() {
int items[] = {4, 3, 1, 2}; compare_class functor; sort_ints(items, sizeof(items)/sizeof(int), functor);
}
http://en.wikipedia.org/wiki/Function_object http://en.wikipedia.org/wiki/Callback_(computer_science)