C
Christopher
I used to just use a plain old function pointer is a call to
std::sort.
My colleagues are telling me that I need to use a "functor". Ok, I
google and see that a functor is a class with a public method,
operator () that does the comparison. Fine, no problem. What they fail
to tell me is, what is the advantage to wrapping some comparison
function in a class and calling it operator()?
I also read that "functors" are supposed to be a class that wraps a
function pointer and additionally holds a state. What kind of state,
what is the typical scenario? I don't see any state data in any of my
colleagues code...
I also googled for examples on doing a sort upon a vector using this
concept of a functor to get the syntax correct. I notice that one
example derives his functor from std::binary_function. Google
binary_function and see that it is described as "a base class for a
functor", well that doesn't tell me much. Why do some of the examples
I've found derive from std::binary_function while others do not?
Thanks!
std::sort.
My colleagues are telling me that I need to use a "functor". Ok, I
google and see that a functor is a class with a public method,
operator () that does the comparison. Fine, no problem. What they fail
to tell me is, what is the advantage to wrapping some comparison
function in a class and calling it operator()?
I also read that "functors" are supposed to be a class that wraps a
function pointer and additionally holds a state. What kind of state,
what is the typical scenario? I don't see any state data in any of my
colleagues code...
I also googled for examples on doing a sort upon a vector using this
concept of a functor to get the syntax correct. I notice that one
example derives his functor from std::binary_function. Google
binary_function and see that it is described as "a base class for a
functor", well that doesn't tell me much. Why do some of the examples
I've found derive from std::binary_function while others do not?
Thanks!