On Tue, 06 Mar 2007 04:14:57 -0800, adrian.hawryluk wrote:
On Mar 5, 2:07 pm, "mlimber" <mlim...@gmail.com> wrote:
On Mar 5, 12:15 pm, "arnuld" <geek.arn...@gmail.com> wrote:
i see the use of pointers, from K&R2 but what is the use of:
2. pointer to function:
int (*fp) (char*);
These are useful for callbacks, generic programming (e.g. with
std::for_each), etc. See also "functors".
Noooooooooo! This is a function pointer. Functors are related to
objects as in:
class A {
int stateVar;
public: int operator()(int x, int y);
};
That is a functor, it allows an object to act like a function, and
since it has it's own state, it could be used in place of this model
of a function:
mlimber didn't say "This is a function pointer", s/he said "See also
functors" - but didn't say why! Perhaps there's a point to be made along
the lines that functors are frequently used in C++ to provide more elegant
solutions to callbacks, generic programming, etc. than can be achieved
with function pointers, or to "wrap" function pointers to hide ugly
implementation details or provide generic interfaces.
Just my tuppence worth.
Precisely.