N
nsgi_2004
Hi,
I have been learning about functors and at first everything was clear. Make
a class and overload operator () so that an object of the functor can be
thought of as a function.
However, I have seen in Effective STL, Scott passes normal functions into
places that expect functors. I'm not sure how this works, as I thought
functors had to be classes.
The only thing I can think of is that, because the STL algorithms are
templated, the template algorithm function will create a function with a
parameter that takes a pointer to the function being passed in as a functor.
I suppose now that I think about it, the compiler would know the function
type and could do this. If so this is very cool, because for a long time
I've needed this sort of functionality and had to resort to weird hacks.
Thanks in advance.
I have been learning about functors and at first everything was clear. Make
a class and overload operator () so that an object of the functor can be
thought of as a function.
However, I have seen in Effective STL, Scott passes normal functions into
places that expect functors. I'm not sure how this works, as I thought
functors had to be classes.
The only thing I can think of is that, because the STL algorithms are
templated, the template algorithm function will create a function with a
parameter that takes a pointer to the function being passed in as a functor.
I suppose now that I think about it, the compiler would know the function
type and could do this. If so this is very cool, because for a long time
I've needed this sort of functionality and had to resort to weird hacks.
Thanks in advance.